?? newtype.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 csk
* @version 1.0
*/
public class NewType {
public NewType() {
}
/**添加一個新類別
*
* @param type(類別對象實例)
* @return 無
*/
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();
}
/**更新一個類別
*
* @param type(類別對象實例)
* @return 無
*/
public void updateType(Type type)
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="update type set type_name=?,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();
}
/**根據類別id刪除該類別,調用NewProject中的刪除方法delProjectTypeid(typeid)
* 刪除項目_類別關聯表中的記錄,調用NewProduct中的delProductUpid(typeid)
* 刪除該類別下的所有產品
*
* @param typeid
*/
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 newpd=new NewProduct();
newpd.delProductUpid(typeid);
newpd.freeCon();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
}
/** 獲得所有的類別集合
* @param 無
* @return Vector類別集合
*/
public Vector getTypeList()
{
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from type";
try {
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next())
{
Type type=new Type();
type.setType_id(rs.getLong("type_id"));
type.setType_name(rs.getString("type_name"));
type.setType_content(rs.getString("type_content"));
list.add(type);
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return list;
}
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 + -