一、建包
二、主界面代码
三、dao方法
@Override
public void updateBook(Book book) {
Connection con = null;
PreparedStatement ps = null;
String sql = "update t_book set bookname=?,price=?, booktype=? where id=?";
try {
con = DBHelper.getCon();
ps = con.prepareStatement(sql);
ps.setString(1, book.getBookname());
ps.setBigDecimal(2, book.getPrice());
ps.setString(3, book.getBooktype());
ps.setInt(4, book.getId());
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBHelper.myClose(con, ps, null);
}
}
@Override
public void delBook(Integer id) {
Connection con = null;
PreparedStatement ps = null;
String sql = "delete from t_book where id=?";
try {
con = DBHelper.getCon();
ps = con.prepareStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBHelper.myClose(con, ps, null);
}
————————————————
版权声明:本文为CSDN博主「longsiqi–」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/emmhao/article/details/124219110