📄 tnotemgr.java
字号:
package dbmgr;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import userbean.Tnote;
public class TnoteMgr {
DBConMgr db_conn=new DBConMgr();
public Collection query(String tname)
{
//System.out.println("sss");
db_conn.ConnectDB();
Collection showlist=new ArrayList();
ResultSet rs = null;
try{
//String sql="select * from moolu3 where tname='"+tname+"'";
String sql="select * from moolu3 where 1=1" +tname+ "";
rs = db_conn.stmt.executeQuery(sql);
//System.out.println(sql);
Tnote tnote = null;
while(rs.next()){
tnote=new Tnote();
tnote.setPxid(rs.getInt("pxid"));
tnote.setTname(rs.getString("tname"));
tnote.setLeibieid(rs.getInt("leibieid"));
tnote.setDept(rs.getString("dept"));
tnote.setStarttime(rs.getString("starttime"));
tnote.setEndtime(rs.getString("endtime"));
tnote.setTraincm(rs.getString("traincm"));
tnote.setTgrade(rs.getInt("tgrade"));
tnote.setTorgan(rs.getString("torgan"));
tnote.setKeshi(rs.getInt("keshi"));
tnote.setIsover(rs.getString("isover"));
tnote.setBeizhu(rs.getString("beizhu"));
showlist.add(tnote);
}
return showlist;
}
catch (SQLException SqlE) {
SqlE.printStackTrace();
return null;
}
catch (Exception E) {
E.printStackTrace();
return null;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
public Collection getAll(){
db_conn.ConnectDB();
Collection showlist=new ArrayList();
ResultSet rs = null;
try{
String sql="select * from moolu3 order by pxid asc";
rs = db_conn.stmt.executeQuery(sql);
Tnote tnote = null;
while(rs.next())
{
tnote=new Tnote();
tnote.setPxid(rs.getInt("pxid"));
tnote.setTname(rs.getString("tname"));
tnote.setLeibieid(rs.getInt("leibieid"));
tnote.setDept(rs.getString("dept"));
tnote.setStarttime(rs.getString("starttime"));
tnote.setEndtime(rs.getString("endtime"));
tnote.setTraincm(rs.getString("traincm"));
tnote.setTgrade(rs.getInt("tgrade"));
tnote.setTorgan(rs.getString("torgan"));
tnote.setKeshi(rs.getInt("keshi"));
tnote.setIsover(rs.getString("isover"));
tnote.setBeizhu(rs.getString("beizhu"));
showlist.add(tnote);
}
return showlist;
}
catch (SQLException SqlE) {
SqlE.printStackTrace();
return null;
}
catch (Exception E) {
E.printStackTrace();
return null;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
public int add(Tnote tnote)
{
db_conn.ConnectDB();
try {
String sql = "insert into moolu3(pxid,tname,leibieid,dept," +
"starttime,endtime,traincm,tgrade,torgan,keshi," +
"isover,beizhu) values("+tnote.getPxid()
+",'" + tnote.getTname()
+ "'," + tnote.getLeibieid()
+",'"+tnote.getDept()
+"','"+tnote.getStarttime()
+"','"+tnote.getEndtime()
+"','"+tnote.getTraincm()
+"',"+tnote.getTgrade()
+",'"+tnote.getTorgan()
+"',"+tnote.getKeshi()
+",'"+tnote.getIsover()
+"','"+tnote.getBeizhu()+"')";
int i = db_conn.stmt.executeUpdate(sql); // 执行sql语句
//String sql1="select * from moolu3";
//System.out.println(sql1);
//System.out.println("111");
return i;
}
catch (SQLException SqlE){
SqlE.printStackTrace();
return -1;
}
catch (Exception E) {
E.printStackTrace();
return -2;
}
finally {
// 关闭连接,释放数据库资源:
db_conn.CloseDB();
}
}
public int chang(Tnote tnote)
{
db_conn.ConnectDB();
try {
String sql = "update moolu3 set tname='"+
tnote.getTname()+ "',dept='"+
tnote.getDept()+ "',starttime='"+
tnote.getStarttime()+ "',leibieid= "+
tnote.getLeibieid()+ ",endtime='"+
tnote.getEndtime()+ "',traincm='"+
tnote.getTraincm()+ "',tgrade="+
tnote.getTgrade()+ ",torgan='"+
tnote.getTorgan()+ "',keshi="+
tnote.getKeshi()+ ",isover='"+
tnote.getIsover()+ "',beizhu='"+
tnote.getBeizhu()+ "' where pxid=" + tnote.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 moolu3 where pxid="+pxid+"";
int i = db_conn.stmt.executeUpdate(sql);
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 moolu3 order by pxid asc";
rs = db_conn.stmt.executeQuery(sql);
Tnote tnote = null;
int i=1;
while(rs.next())
{
if((i>=start)&&(i<start+size))
{tnote=new Tnote();
tnote.setPxid(rs.getInt("pxid"));
tnote.setTname(rs.getString("tname"));
tnote.setLeibieid(rs.getInt("leibieid"));
tnote.setDept(rs.getString("dept"));
tnote.setStarttime(rs.getString("starttime"));
tnote.setEndtime(rs.getString("endtime"));
tnote.setTraincm(rs.getString("traincm"));
tnote.setTgrade(rs.getInt("tgrade"));
tnote.setKeshi(rs.getInt("keshi"));
tnote.setIsover(rs.getString("isover"));
tnote.setBeizhu(rs.getString("beizhu"));
showlist.add(tnote);
}
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 + -