-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemberDAO_JDBC.java
More file actions
55 lines (48 loc) · 1.26 KB
/
Copy pathMemberDAO_JDBC.java
File metadata and controls
55 lines (48 loc) · 1.26 KB
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
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
public class MemberDAO_JDBC implements MemberDAO
{
Connection dbConnection;
public MemberDAO_JDBC(Connection dbconn)
{
dbConnection = dbconn;
}
@Override
public void addMember(Member m)
{
PreparedStatement prepstmt = null;
String sql = "INSERT IGNORE INTO member(mid, fname, minit, lname, memberType, addr, phoneno, noofbooksissued, maxissued) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
try
{
prepstmt = dbConnection.prepareStatement(sql);
prepstmt.setInt(1, m.getId());
prepstmt.setString(2, m.getFname());
prepstmt.setString(3, Character.toString(m.getMInit()));
prepstmt.setString(4, m.getLname());
prepstmt.setString(5, m.getMemberType());
prepstmt.setString(6, m.getAddr());
prepstmt.setString(7, m.getPhoneNo());
prepstmt.setInt(8, m.getBooksIssuedCount());
prepstmt.setInt(9, m.getMaxIssuedCount());
prepstmt.executeUpdate();
//dbConnection.commit();
System.out.println("Member "+m.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());
}
}
}