📄 newtype.java~1~
字号:
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 csk
* @version 1.0
*/
public class NewType {
public NewType() {
}
public void addType(Type type)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
long maxid=0;
try {
PreparedStatement ps1 = con.prepareStatement("select max(type_id) as id from type");
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 type(type_id,type_name,Type_content) values(?,?,?)";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,maxid);
ps.setString(2,type.getType_name());
ps.setString(3,type.getType_content() );
ps.executeUpdate();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
}
public void updateType(Type type)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="update type set type_name=?,set type_content=? where type_id=?";
try {
ps=con.prepareStatement(sql);
ps.setString(1,type.getType_name());
ps.setString(2,type.getType_content());
ps.setLong(3,type.getType_id());
ps.executeUpdate();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
}
public void delType(long typeid)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="delete from type where type_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,typeid);
ps.executeUpdate();
NewProject newpj=new NewProject(); //调用NewProject中的删除方法
newpj.delProjectTypeid(typeid);
newpj.freeCon();
//删除所有的该类产品调用NewProduct中方法
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
}
public static void main(String[] args) {
NewType newType1 = new NewType();
}
/**
* 释放数据库资源<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 + -