-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathBookDao.java
More file actions
87 lines (74 loc) · 2.57 KB
/
Copy pathBookDao.java
File metadata and controls
87 lines (74 loc) · 2.57 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package mainlibrary;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class BookDao {
public static int save(String callno,String name,String author,String publisher,int quantity){
int status=0;
try{
Connection con=DB.getConnection();
PreparedStatement ps=con.prepareStatement("insert into books(callno,name,author,publisher,quantity) values(?,?,?,?,?)");
ps.setString(1,callno);
ps.setString(2,name);
ps.setString(3,author);
ps.setString(4,publisher);
ps.setInt(5,quantity);
status=ps.executeUpdate();
con.close();
}catch(Exception e){System.out.println(e);}
return status;
}
/**
*
* @param Publisher
* @return
*/
public static boolean PublisherValidate( String Publisher)
{
boolean status = false;
try(Connection con = DB.getConnection()) {
PreparedStatement ps = con.prepareStatement("select * from Publisher where PublisherName = ?");
ps.setString(1, Publisher);
ResultSet rs=ps.executeQuery();
status=rs.next();
con.close();
}catch(Exception e){System.out.println(e);}
return status;
}
public static int AddPublisher( String Publisher)
{
int status= 0;
try(Connection con = DB.getConnection()) {
PreparedStatement ps=con.prepareStatement("insert into Publisher(PublisherName) values(?)");
ps.setString(1,Publisher);
status=ps.executeUpdate();
con.close();
}catch(Exception e){System.out.println(e);}
return status;
}
public static int SaveBook(String BookN, String AuthorN, String PublisherN, String ShelfN, String RowN, String GenreN) {
int status= 0;
try(Connection con = DB.getConnection()) {
PreparedStatement ps=con.prepareStatement("insert into Books(BookName,Author,Genre,Publisher,Shelf, Row) values(?,?,?,?,?,?)");
ps.setString(1,BookN);
ps.setString(2, AuthorN);
ps.setString(3, GenreN);
ps.setString(4, PublisherN);
ps.setString(5, ShelfN);
ps.setString(6, RowN);
status=ps.executeUpdate();
con.close();
}catch(Exception e){System.out.println(e);}
return status; }
public static int Delete(int BookID)
{
int status= 0;
try(Connection con = DB.getConnection()) {
PreparedStatement ps=con.prepareStatement("DELETE FROM Books where BookID=?");
ps.setInt(1,BookID);
status=ps.executeUpdate();
con.close();
}catch(Exception e){System.out.println(e);}
return status;
}
}