📄 newprice.java
字号:
package zhaobiao.db;
import java.util.*;
import java.sql.*;
import zhaobiao.db.*;
import zhaobiao.data.*;
/**
* <p>Title: 厂商信息管理类</p>
* <p>Description: 有关厂商信息管理的浏览操作</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class NewPrice {
public NewPrice() {
}
/**添加一条标价记录
*
* @param price(price对象实例)
* @return 无
*/
public void addPrice(Price price) {
db = DBConnectionManager.getInstance();
con = db.getConnection("idb");
long maxid = 0;
try {
PreparedStatement ps1 = con.prepareStatement(
"select max(price_id) as id from price");
rs = ps1.executeQuery();
if (rs.next()) {
maxid = rs.getLong("id") + 1;
}
else
maxid = 1;
if (ps1 != null)
ps1.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}
String sql =
"insert into price(price_id,t1,t2,t3,t4,t5,t6,t7,t8)values(?,?,?,?,?,?,?,?,?)";
try {
ps = con.prepareStatement(sql);
ps.setLong(1, maxid);
ps.setString(2, price.getDevice_price());
ps.setString(3, price.getTool_price());
ps.setString(4, price.getService_price());
ps.setString(5, price.getOptional_price());
ps.setString(6, price.getRePro_price());
ps.setString(7, price.getInter_price());
ps.setString(8, price.getEnsure_price());
ps.setString(9, price.getDeliver_time());
ps.executeUpdate();
}
catch (SQLException ex) {
ex.printStackTrace();
}
freeCon();
}
/**根据标价id删除该标价记录
*
* @param price_id
* @return 无
*/
public void delPrice(long price_id) {
db = DBConnectionManager.getInstance();
con = db.getConnection("idb");
String sql = "delete from price where price_id=?";
try {
ps = con.prepareStatement(sql);
ps.setLong(1, price_id);
ps.executeUpdate();
}
catch (SQLException ex) {
ex.printStackTrace();
}
freeCon();
}
/**更新一条标价记录
*
* @param price
* @return 无
*/
public void updatePrice(Price price) {
db = DBConnectionManager.getInstance();
con = db.getConnection("idb");
String sql =
"update price set t1=?,t2=?,t3=?,t4=?,t5=?,t6=?,t7=?,t8=? where price_id=?";
try {
ps = con.prepareStatement(sql);
ps.setString(1, price.getDevice_price());
ps.setString(2, price.getTool_price());
ps.setString(3, price.getService_price());
ps.setString(4, price.getOptional_price());
ps.setString(5, price.getRePro_price());
ps.setString(6, price.getInter_price());
ps.setString(7, price.getEnsure_price());
ps.setString(8, price.getDeliver_time());
ps.setLong(9, price.getPrice_id());
ps.executeUpdate();
}
catch (SQLException ex) {
ex.printStackTrace();
}
freeCon();
}
/**获得标价表中的最大id(maxid)
* @param 无
* @return long
*/
public long getMaxid() {
db = DBConnectionManager.getInstance();
con = db.getConnection("idb");
long maxid = 0;
try {
PreparedStatement ps1 = con.prepareStatement(
"select max(price_id) as id from price");
rs = ps1.executeQuery();
if (rs.next()) {
maxid = rs.getLong("id");
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
freeCon();
return maxid;
}
public static void main(String[] args) {
NewPrice newPrice1 = new NewPrice();
}
/**
* 释放数据库资源<p>
*PreparedStatement和ResultSep将关闭,Connection返回给连接池
* @param 无
* @repurn 无
* @exception SQLException
*
*/
public void freeCon() {
try {
if (rs != null)
rs.close();
if (ps != null)
ps.close();
}
catch (SQLException ex) {
}
if (db != null)
db.freeConnection("idb", con);
}
private PreparedStatement ps = null;
private DBConnectionManager db;
private Connection con = null;
private ResultSet rs = null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -