📄 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 + -