-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookCopyDAO_JDBC.java
57 lines (51 loc) · 1.16 KB
/
BookCopyDAO_JDBC.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
public class BookCopyDAO_JDBC implements BookCopyDAO
{
Connection dbConnection;
public BookCopyDAO_JDBC(Connection dbconn)
{
dbConnection = dbconn;
}
@Override
public void addBookCopy(Book b)
{
PreparedStatement prepstmt = null;
BookCopy bc = new BookCopy();
String sql;
sql = "INSERT IGNORE INTO bookcopy(ebid, copyid, status) VALUES (?, ?, ?);";
try
{
prepstmt = dbConnection.prepareStatement(sql);
for(int i=1;i<=b.getTotalCount();i++)
{
bc.setId(b.getId());
bc.setCopyId(i);
bc.setStatus(true);
prepstmt.setInt(1, bc.getId());
prepstmt.setString(2, bc.getCopyId());
prepstmt.setBoolean(3, bc.getStatus());
prepstmt.executeUpdate();
//dbConnection.commit();
System.out.println("Book copies of "+bc.getCopyId()+" added to the database");
}
System.out.println("Book copies of "+b.getId()+" added to the database");
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
try
{
if(prepstmt!=null)
{
prepstmt.close();
}
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
}