📄 csmgr.java
字号:
package dbmgr;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import userbean.Starff;
import dbmgr.DBConMgr;
public class CsMgr {
DBConMgr db_conn=new DBConMgr();
public Collection search(String certiname)
{
db_conn.ConnectDB();
Collection showlist=new ArrayList();
ResultSet rs = null;
try{
String sql="select * from yoou where 1=1" +certiname+ "";
//System.out.println(sql);
rs = db_conn.stmt.executeQuery(sql);
Starff starff = null;
while(rs.next())
{
starff=new Starff();
starff.setPxid(rs.getInt("pxid"));
starff.setLeibieid(rs.getInt("leibieid"));
starff.setCertiname(rs.getString("certiname"));
starff.setCertinum(rs.getString("certinum"));
starff.setCertidate(rs.getString("certidate"));
showlist.add(starff);
}
return showlist;
}
catch (SQLException SqlE) {
SqlE.printStackTrace();
return null;
}
catch (Exception E) {
E.printStackTrace();
return null;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
public Collection getAll(){
//System.out.println("11111111");
db_conn.ConnectDB();
Collection showlist=new ArrayList();
ResultSet rs = null;
try{
String sql="select * from yoou order by pxid asc";
rs = db_conn.stmt.executeQuery(sql);
Starff starff = null;
while(rs.next())
{
starff=new Starff();
starff.setPxid(rs.getInt("pxid"));
starff.setLeibieid(rs.getInt("leibieid"));
starff.setCertiname(rs.getString("certiname"));
starff.setCertinum(rs.getString("certinum"));
starff.setCertidate(rs.getString("certidate"));
showlist.add(starff);
}
return showlist;
}
catch (SQLException SqlE) {
SqlE.printStackTrace();
return null;
}
catch (Exception E) {
E.printStackTrace();
return null;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
public int insert(Starff starff)
{
//System.out.println("111");
db_conn.ConnectDB();
try {
String sql = "insert into yoou(pxid,leibieid,certiname" +
",certinum,certidate) values("+starff.getPxid()
+"," + starff.getLeibieid()
+ ",'" + starff.getCertiname()
+"','" + starff.getCertinum()
+"','" +starff.getCertidate()+"')";
//System.out.println(sql);
int i = db_conn.stmt.executeUpdate(sql); // 执行sql语句
//System.out.println("2555555");
return i;
}
catch (SQLException SqlE){
SqlE.printStackTrace();
return -1;
}
catch (Exception E) {
E.printStackTrace();
return -2;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
public int chang(Starff starff)
{
//System.out.println("111");
db_conn.ConnectDB();
try {
String sql = "update yoou set pxid="+
starff.getPxid()+",leibieid="+
starff.getLeibieid()+",certiname='"+
starff.getCertiname()+"',certinum='"+
starff.getCertinum()+"',certidate='"+
starff.getCertidate()+"' where pxid="+
starff.getPxid()+"";
int i = db_conn.stmt.executeUpdate(sql); // 执行sql语句
// System.out.println(sql);
return i;
}
catch (SQLException SqlE){
SqlE.printStackTrace();
return -1;
}
catch (Exception E) {
E.printStackTrace();
return -2;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
public int delete(int pxid)
{
db_conn.ConnectDB();
try {
String sql="delete from yoou where pxid=" +pxid+ "";
int i = db_conn.stmt.executeUpdate(sql);
//System.out.println("dedegdf");
return i;
}
catch (SQLException SqlE){
SqlE.printStackTrace();
return -1;
}
catch (Exception E) {
E.printStackTrace();
return -2;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
public Collection getPage(int start,int size)
{
//System.out.println(start+","+size);
db_conn.ConnectDB();
Collection showlist=new ArrayList();
ResultSet rs = null;
try{
String sql="select * from yoou order by pxid asc";
rs = db_conn.stmt.executeQuery(sql);
Starff starff = null;
int i=1;
while(rs.next())
{
if((i>=start)&&(i<start+size))
{starff=new Starff();
starff.setPxid(rs.getInt("pxid"));
starff.setLeibieid(rs.getInt("leibieid"));
starff.setCertiname(rs.getString("certiname"));
starff.setCertinum(rs.getString("certinum"));
starff.setCertidate(rs.getString("certidate"));
showlist.add(starff);
}
i=i+1;
}
return showlist;
}
catch (SQLException SqlE) {
SqlE.printStackTrace();
return null;
}
catch (Exception E) {
E.printStackTrace();
return null;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -