📄 newproduct.java~9~
字号:
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 csk
* @version 1.0
*/
public class NewProduct {
public NewProduct() {
}
public static void main(String[] args) {
NewProduct newProduct1 = new NewProduct();
}
public void addProduct(Product pd)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
long maxid=0;
try {
PreparedStatement ps1 = con.prepareStatement("select max(product_id) as id from product");
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 product(product_id,product_name,type_id,product_content,maker_id)values(?,?,?,?,?)";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,maxid);
ps.setString(2,pd.getProduct_name()) ;
ps.setLong(3,pd.getType_id());
ps.setString(4,pd.getProduct_content());
ps.setLong(5,pd.getMaker_id());
ps.executeUpdate();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
}
public void delProductid(long pdid)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="delete from product where product_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,pdid);
ps.executeUpdate();
//删除所有的ppm表中的该产品记录
NewPPM newppm=new NewPPM();
newppm.delPPMProductid(pdid);
newppm.freeCon();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
}
/**更新一个产品信息
*
*
*/
public void upateProduct(Product pd)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="update product set product_name=?,type_id=?,product_content=?,maker_id=? where product_id=?";
try {
ps=con.prepareStatement(sql);
ps.setString(1,pd.getProduct_name());
ps.setLong(2,pd.getType_id());
ps.setString(3,pd.getProduct_content());
ps.setLong(4,pd.getMaker_id());
ps.setLong(5,pd.getProduct_id());
ps.executeUpdate();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
}
/**根据typeid删除产品表中的有关产品
*
* @param typeid
*/
public void delProductUpid(long typeid)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="delete from product where type_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,typeid);
ps.executeUpdate();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
}
public Vector getProductMakerid(long maker_id)
{
Basic basic=new Basic();
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from product where maker_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,maker_id);
rs=ps.executeQuery();
while(rs.next())
{
Product pd=new Product();
pd.setProduct_id(rs.getLong("product_id"));
pd.setProduct_name(rs.getString("product_name"));
pd.setType_id(rs.getLong("type_id"));
pd.setProduct_content(rs.getString("product_content"));
pd.setMaker_id(rs.getLong("maker_id"));
list.add(pd);
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
freeCon();
return list;
}
/**
* 释放数据库资源<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 + -