📄 bookinfoimple.java
字号:
package service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javabean.BookInfo;
import conn.*;
public class BookInfoImple implements IBookInfo{
private JdbcTool tool;
private Statement stm;
private String sql;
private ResultSet rs;
//private boolean k;
public BookInfoImple() {
tool = new JdbcTool();
stm = tool.getStatement();
}
public void add(BookInfo book) {
sql = "insert into bookinfo(name,price,author,date,bookman) values('"+book.getName()+"',"+book.getPrice()+",'"+book.getAuthor()+"','"+book.getDate()+"','"+book.getBookman()+"')";
try {
stm.execute(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet query() {
sql = "select * from bookinfo";
try {
rs = stm.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public void delById(int id) {
sql = "delete from bookinfo where id='"+id+"'";
try {
stm.execute(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int update(String name, int price, String author, String date,
String bookman, int id) {
sql = "update bookinfo set name='"+name+"',price="+price+",author='"+author+"',date='"+date+"',bookman='"+bookman+"' where id="+id;
int count = 0;
try {
count = stm.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return count;
}
public ResultSet queryByAuthor(String author) {
sql = "select * from bookinfo where author='"+author+"'";
try {
rs = stm.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet queryByBookman(String bookman) {
sql = "select * from bookinfo where bookman='"+bookman+"'";
try {
rs = stm.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet queryByDate(String date) {
sql = "select * from bookinfo where date='"+date+"'";
try {
rs = stm.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet queryByName(String name) {
sql = "select * from bookinfo where name='"+name+"'";
try {
rs = stm.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet queryById(int id) {
sql = "select * from bookinfo where id='"+id+"'";
try {
rs = stm.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -