📄 testtype.java
字号:
package javaBeanClass.TestType;
import javaBeanClass.DatabaseConn;
import javaBeanClass.TestType.TestTypeData;
import java.util.*;
import java.sql.*;
public class TestType
{
private DatabaseConn db;
private int pageNumber=1;//要显示的页码数,默认为1
private int totalPage;//总页数
private int ID;
private String Project_CN;
private String Memo;
private String Del;
private String sql;
public void setPageNumber(int pageNumber){this.pageNumber=pageNumber;}
public int getPageNumber(){return this.pageNumber;}
public void setTotalPage(int totalPage){this.totalPage=totalPage;}
public int getTotalPage(){return this.totalPage;}
public void setID(int ID){this.ID=ID;}
public int getID(){return this.ID;}
public void setProject_CN(String Project_CN) throws Exception
{try{this.Project_CN=new String(Project_CN.getBytes("8859_1"),"GB2312");}catch(Exception e){throw new Exception("编码失败!");}}
public String getProject_CN(){return this.Project_CN;}
public void setMemo(String Memo)throws Exception
{try{this.Memo=new String(Memo.getBytes("8859_1"),"GB2312");}catch(Exception e){throw new Exception("编码失败!");}}
public String getMemo(){return this.Memo;}
public void setDel(String Del){this.Del=Del;}
public String getDel(){return this.Del;}
public TestType(){db=new DatabaseConn();}
public TestTypeData findByPrimaryKey()throws SQLException
{
sql="select * from TestType where ID=?";
Connection con;
PreparedStatement ps=null;
ResultSet rs=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareStatement(sql);
ps.setInt(1,ID);
rs=ps.executeQuery();
if(rs.next())
{return new TestTypeData(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4));}
}
catch(Exception ex)
{
System.out.println("FindByPrimaryKey TestType failed:"+ex.getMessage());
throw new SQLException("FindByPrimaryKey TestType failed!");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("FindByPrimaryKey Close TestType Error:"+sqlex.getMessage());}
}
return null;
}
public Vector findAll()throws SQLException
{
Vector vResults=new Vector(1,1);
boolean bResult=false;
sql="select * from TestType where Del='0'";
Connection con;
PreparedStatement ps=null;
ResultSet rs=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
bResult=rs.next();
if(bResult)
{
do
{
vResults.add(new TestTypeData(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4)));
}while(rs.next());
}
}
catch(Exception ex)
{
System.out.println("FindAll TestType failed:"+ex.getMessage());
throw new SQLException("FindAll TestType failed!");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("FindAll Close TestType Error:"+sqlex.getMessage());}
}
if(bResult)
{return vResults;}
else
{return null;}
}
public Vector findAll(int pageSizes)throws SQLException
{
String whereStr="where Del='0' ";
String orderByStr="order by ID";
Vector vResults=new Vector(1,1);
boolean bResult=false;
//sql="select * from View_TestType where Del='0' "+((this.TestTypeID==0)?"":(" And TestTypeID="+this.TestTypeID));
Connection con;
CallableStatement ps=null;
ResultSet rs=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareCall("{call pr_splitPage(?,?,?,?,?)}");
ps.registerOutParameter(1,java.sql.Types.INTEGER);
ps.setString(2,"TestType");
ps.setInt(3,88888888);//用于返回总页数
ps.setInt(4,pageSizes);
ps.setString(5,whereStr);
ps.executeUpdate();//首先返回总页数,存储过程不能即返回总页数又返回记录集,具体用法还要再研究
this.totalPage=ps.getInt(1);
ps=con.prepareCall("{call pr_splitPage(?,?,?,?,?,?)}");
ps.registerOutParameter(1,java.sql.Types.INTEGER);//用于返回记录集,此参数可不带
ps.setString(2,"TestType");
ps.setInt(3,pageNumber);
ps.setInt(4,pageSizes);
ps.setString(5,whereStr);
ps.setString(6,orderByStr);
rs=ps.executeQuery();
bResult=rs.next();
if(bResult)
{
do
{
vResults.add(new TestTypeData(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4)));
}while(rs.next());
}
}
catch(Exception ex)
{
System.out.println("FindAll TestType failed:"+ex.getMessage());
throw new SQLException("FindAll TestType failed!");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("FindAll Close TestType Error:"+sqlex.getMessage());}
}
if(bResult)
{return vResults;}
else
{return null;}
}
public Vector findAllDeleted(int pageSizes)throws SQLException
{
String whereStr="where Del='1' ";
String orderByStr="order by ID";
Vector vResults=new Vector(1,1);
boolean bResult=false;
//sql="select * from View_TestType where Del='1'"+((this.TestTypeID==0)?"":(" And TestTypeID="+this.TestTypeID));
Connection con;
CallableStatement ps=null;
ResultSet rs=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareCall("{call pr_splitPage(?,?,?,?,?)}");
ps.registerOutParameter(1,java.sql.Types.INTEGER);
ps.setString(2,"TestType");
ps.setInt(3,88888888);//用于返回总页数
ps.setInt(4,pageSizes);
ps.setString(5,whereStr);
ps.executeUpdate();//首先返回总页数,存储过程不能即返回总页数又返回记录集,具体用法还要再研究
this.totalPage=ps.getInt(1);
ps=con.prepareCall("{call pr_splitPage(?,?,?,?,?,?)}");
ps.registerOutParameter(1,java.sql.Types.INTEGER);//用于返回记录集,此参数可不带
ps.setString(2,"TestType");
ps.setInt(3,pageNumber);
ps.setInt(4,pageSizes);
ps.setString(5,whereStr);
ps.setString(6,orderByStr);
rs=ps.executeQuery();
bResult=rs.next();
if(bResult)
{
do
{
vResults.add(new TestTypeData(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4)));
}while(rs.next());
}
}
catch(Exception ex)
{
System.out.println("FindAllDeleted TestType failed:"+ex.getMessage());
throw new SQLException("FindAllDeleted TestType failed!");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("FindAllDeleted Close TestType Error:"+sqlex.getMessage());}
}
if(bResult)
{return vResults;}
else
{return null;}
}
public Vector findAllDeleted()throws SQLException
{
Vector vResults=new Vector(1,1);
boolean bResult=false;
sql="select * from TestType where Del='1'";
Connection con;
PreparedStatement ps=null;
ResultSet rs=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
bResult=rs.next();
if(bResult)
{
do
{
vResults.add(new TestTypeData(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4)));
}while(rs.next());
}
}
catch(Exception ex)
{
System.out.println("FindAllDeleted TestType failed:"+ex.getMessage());
throw new SQLException("FindAllDeleted TestType failed!");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("FindAllDeleted Close TestType Error:"+sqlex.getMessage());}
}
if(bResult)
{return vResults;}
else
{return null;}
}
public void insert()throws SQLException
{
sql="insert into TestType (Project_CN,Memo) values(?,?)";
Connection con;
PreparedStatement ps=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
boolean bTemp;
try
{
ps=con.prepareStatement(sql);
ps.setString(1,Project_CN);
ps.setString(2,Memo);
int rowCount=ps.executeUpdate();
if(rowCount==0)
{
throw new SQLException("Insert TestType failed!");
}
}
catch(SQLException sqlex)
{
System.out.println("Insert TestType Error:"+sqlex.getMessage());
throw new SQLException(sqlex.getMessage());
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("Insert Close TestType Error:"+sqlex.getMessage());}
}
}
public void update()throws SQLException,Exception
{
sql="update TestType set Project_CN=?,Memo=? where ID=?";
Connection con;
PreparedStatement ps=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareStatement(sql);
ps.setString(1,Project_CN);
ps.setString(2,Memo);
ps.setInt(3,ID);
int rowCount=ps.executeUpdate();
if(rowCount==0)
{
throw new SQLException("Update TestType failed!");
}
}
catch(SQLException sqlex)
{
System.err.println("Update TestType Error:"+sqlex.getMessage());
throw new SQLException("Update TestType Error");
}
catch(Exception e)
{
System.out.println("Other Of Update TestType Error:"+e.getMessage());
throw new Exception("Other Of Update TestType Error");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("Update Close TestType Error:"+sqlex.getMessage());}
}
}
public void delete()throws SQLException
{
sql="update TestType set Del='1' where ID=?";
Connection con;
PreparedStatement ps=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareStatement(sql);
ps.setInt(1,ID);
int rowCount=ps.executeUpdate();
if(rowCount==0)
{
throw new SQLException("Delete TestType failed!");
}
}
catch(SQLException sqlex)
{
System.out.println("Delete TestType Error:"+sqlex.getMessage());
throw new SQLException("Delete TestType Error");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("Delete Close TestType Error:"+sqlex.getMessage());}
}
}
public void realDelete()throws SQLException
{
sql="delete TestType where ID=?";
Connection con;
PreparedStatement ps=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareStatement(sql);
ps.setInt(1,ID);
int rowCount=ps.executeUpdate();
if(rowCount==0)
{
throw new SQLException("realDelete TestType failed!");
}
}
catch(SQLException sqlex)
{
System.out.println("realDelete TestType Error:"+sqlex.getMessage());
throw new SQLException("realDelete TestType Error");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("realDelete Close TestType Error:"+sqlex.getMessage());}
}
}
public void restor()throws SQLException
{
sql="update TestType set Del='0' where ID=?";
Connection con;
PreparedStatement ps=null;
try{con=db.connectToDB();}
catch(Exception ex){throw new SQLException("Connect database failed!");}
try
{
ps=con.prepareStatement(sql);
ps.setInt(1,ID);
int rowCount=ps.executeUpdate();
if(rowCount==0)
{
throw new SQLException("Restor TestType failed!");
}
}
catch(SQLException sqlex)
{
System.out.println("Restor TestType Error:"+sqlex.getMessage());
throw new SQLException("Restor TestType Error");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("Restor Close TestType Error:"+sqlex.getMessage());}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -