📄 newprice.java~4~~1~
字号:
package zhaobiao.db;
import java.util.*;
import java.sql.*;
import zhaobiao.db.*;
import zhaobiao.date.*;
/**
* <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() {
}
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.getT1());
ps.setString(3,price.getT2());
ps.setString(4,price.getT3());
ps.setString(5,price.getT4());
ps.setString(6,price.getT5());
ps.setString(7,price.getT6());
ps.setString(8,price.getT7());
ps.setString(9,price.getT8());
ps.executeUpdate();
}
catch (SQLException ex) {
ex.printStackTrace();
}
freeCon();
}
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();
}
public void updatePrice(Price price)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="update price set t1=?,set t2=?,set t3=?,set t4=?,set t5=?,set t6=?,set t7=?,set t8=? where price_id=?";
try {
ps=con.prepareStatement(sql);
ps.setString(1,price.getT1());
ps.setString(2,price.getT2());
ps.setString(3,price.getT3());
ps.setString(4,price.getT4());
ps.setString(5,price.getT5());
ps.setString(6,price.getT6());
ps.setString(7,price.getT7());
ps.setString(8,price.getT8());
ps.setLong(9,price.getPrice_id());
ps.executeUpdate();
}
catch (SQLException ex) {
ex.printStackTrace();
}
freeCon();
}
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 + -