📄 scores.java
字号:
package javaBeanClass.Scores;
import javaBeanClass.Tools;
import javaBeanClass.DatabaseConn;
import javaBeanClass.Scores.ScoresData;
import java.util.*;
import java.sql.*;
public class Scores
{
private DatabaseConn db;
private int pageNumber=1;//要显示的页码数,默认为1
private int totalPage;//总页数
private int ID;
private String Names;//Name是Java的关键字,开始用Name做变量名,一直出错,后改为Names正常
private String SN;
private float Scores;
private String Project_CN;
private String TestIndexMemo;
private String ClassNumber;
//搜索用变量
private int ClassID;
private int TestTypeID;
private float minScores=-1.0f;//成绩下限
private float maxScores=-1.0f;//成绩上限
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 setNames(String Names)throws SQLException
{try{this.Names=new String(Names.getBytes("8859_1"),"GB2312");}catch(Exception e){throw new SQLException("编码失败!");}}
public String getNames(){return this.Names;}
public void setSN(String SN){this.SN=SN;}
public String getSN(){return this.SN;}
public void setScores(float Scores){this.Scores=Scores;}
public float getScores(){return this.Scores;}
public void setProject_CN(String Project_CN){this.Project_CN=Project_CN;}
public String getProject_CN(){return this.Project_CN;}
public void setTestIndexMemo(String TestIndexMemo){this.TestIndexMemo=TestIndexMemo;}
public String getTestIndexMemo(){return this.TestIndexMemo;}
public void setClassNumber(String ClassNumber){this.ClassNumber=ClassNumber;}
public String getClassNumber(){return this.ClassNumber;}
public void setClassID(int ClassID){this.ClassID=ClassID;}
public int getClassID(){return this.ClassID;}
public void setTestTypeID(int TestTypeID){this.TestTypeID=TestTypeID;}
public int getTestTypeID(){return this.TestTypeID;}
public void setMinScores(float minScores){this.minScores=minScores;}
public void setMaxScores(float maxScores){this.maxScores=maxScores;}
public Scores(){db=new DatabaseConn();}
public ScoresData findByPrimaryKey()throws SQLException
{
sql="select * from View_Scores 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 ScoresData(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getFloat(4),rs.getString(5),rs.getString(6),rs.getString(7));}
}
catch(Exception ex)
{
System.out.println("FindByPrimaryKey Scores failed:"+ex.getMessage());
throw new SQLException("FindByPrimaryKey Scores failed!");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("FindByPrimaryKey Close Scores Error:"+sqlex.getMessage());}
}
return null;
}
public Vector findAll(int pageSizes)throws SQLException
{
String tableName="View_Scores";
String whereStr="where 1=1"+
(this.TestTypeID==0?"":" And TestTypeID="+this.TestTypeID)+
(this.ClassID==0?"":" And ClassID="+this.ClassID)+
(this.SN==null?"":" And SN like '%"+Tools.replace(this.SN,"'","''")+"%'")+
(this.minScores==-1.0?"":" And Scores>="+this.minScores)+
(this.maxScores==-1.0?"":" And Scores<="+this.maxScores)+
(this.Names==null?"":" And Names like '%"+Tools.replace(this.Names,"'","''")+"%'");
String orderByStr="order by TestTypeID,ClassID,SN,Scores,Names";
System.out.println(whereStr);
Vector vResults=new Vector(1,1);
boolean bResult=false;
//sql="select * from Scores where Del='0'";
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,tableName);
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,tableName);
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 ScoresData(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getFloat(4),rs.getString(5),rs.getString(6),rs.getString(7)));
}while(rs.next());
}
}
catch(Exception ex)
{
System.out.println("FindAll Scores failed:"+ex.getMessage());
throw new SQLException("FindAll Scores failed!");
}
finally
{
try{con.close();ps.close();}
catch(SQLException sqlex){System.out.println("FindAll Close Scores Error:"+sqlex.getMessage());}
}
if(bResult)
{return vResults;}
else
{return null;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -