📄 buymanager.java~36~
字号:
package jxc;
/**
* <p>Title: jxc demo</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author cwx
* @version 1.0
*/
import java.sql.*;
public class BuyManager {
public BuyManager() {
}
static public boolean addBuy(String supplierID, String wareID, float buyPrice,
int buyQty, String buyDate, String buyPerson){
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = ConnectionManager.getConnection();
stmt = conn.prepareStatement("insert into Buy (supplierID,wareID,price,quantity,buyDate,buyPerson)"
+" values(?,?,?,?,?,?)");
stmt.setString(1, supplierID);
stmt.setString(2, wareID);
stmt.setFloat(3, buyPrice);
stmt.setInt(4, buyQty);
stmt.setString(5, buyDate);
stmt.setString(6, buyPerson);
stmt.executeUpdate();
//更新库存
stmt.close();
stmt = conn.prepareStatement("select * from Reserve where wareID="+wareID);
ResultSet rs = stmt.executeQuery();
if(rs.next()){//存在库存记录
stmt = conn.prepareStatement("update Reserve set resQty=resQty+" +
buyQty+" where wareID="+wareID);
}
else{
stmt = conn.prepareStatement("update Reserve set resQty=resQty+" +
buyQty);
}
stmt.executeUpdate();
//验证通过
return true;
}
catch (java.sql.SQLException e) {
System.err.println(e);
}
finally {
//关闭数据库资源
if (stmt != null) {
try {
stmt.close();
} catch (Exception exception) {}
}
if (conn != null) {
try {
conn.close();
} catch (Exception exception) {}
}
}
//失败
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -