?? newtype.java
字號:
/**
*
*/
package com.centralsoft.zhaobiao.admin;
import java.sql.*;
import java.util.*;
import com.centralsoft.zhaobiao.qtdataguanli.*;
import com.centralsoft.zhaobiao.util.*;
/**
* @author zw
*
*/
public class NewType {
public NewType() {
}
/**
* 添加一個新類別
* @param type
*/
public void addType(Type type) {
dataBase db = new dataBase();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
long maxid = 0;
conn = db.getConnection();
String sqlResultSet = "select max(type_id) as maxid from type";
String sqlPrepared = "inset into type (type_id,type_name,type_content) " +
"values (?,?,?)";
rs = db.getResultSet(sqlResultSet);
try {
if (rs.next()) {
maxid = rs.getLong("maxid") + 1;
} else {
maxid = 1;
}
System.out.println("添加一個新類別id"+maxid);
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
try {
ps = conn.prepareStatement(sqlPrepared);
ps.setLong(1,maxid);
ps.setString(2,type.getType_name());
ps.setString(3,type.getType_content());
ps.executeUpdate();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
if (ps != null) {
ps.close();
}
db.closeConn();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
/**
* 獲得所有的類別集合
* @return
*/
public Vector getTypeList() {
Vector list = new Vector();
dataBase db = new dataBase();
ResultSet rs = null;
String sql = "select * from type";
rs = db.getResultSet(sql);
try {
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 (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
db.closeConn();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
return list;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -