bookdbdao.java
来自「网上书店 源代码和数据库网上书店 源代码和数据库」· Java 代码 · 共 154 行
JAVA
154 行
package com.shop.model.dao.addbook;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import com.shop.model.utils.DataBaseConn;
public class BookdbDAO {
public void updateDB(String id,int buyCount) {
Connection conn = null;
Statement st = null;
DataBaseConn dataBaseConn = new DataBaseConn();
conn = dataBaseConn.getConnection();
try {
st = conn.createStatement();
String sql = "update bookinfo set remainnumber=remainnumber-"+buyCount+ "where isbn='"
+ id+"'";
st.execute(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(st!=null){
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public void removeBook(String[] ids){
Connection conn = null;
Statement st = null;
DataBaseConn dataBaseConn = new DataBaseConn();
conn = dataBaseConn.getConnection();
try {
st = conn.createStatement();
for (String id : ids) {
String sql = "update bookinfo set remainnumber=remainnumber+1 where isbn='"
+ id+"'";
st.execute(sql);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(st!=null){
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public void addBookCount(String isbn,int num){
Connection conn = null;
Statement st = null;
DataBaseConn dataBaseConn = new DataBaseConn();
conn = dataBaseConn.getConnection();
try {
st = conn.createStatement();
String sql = "update bookinfo set remainnumber=remainnumber+"+num+" where isbn='"
+ isbn+"'";
st.execute(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(st!=null){
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?