📄 cxpdcanzhaobean.java
字号:
package caoxingPingding;
import conn.DataBaseConnection;
import java.sql.*;
import java.util.*;
import java.io.*;
public class CxpdCanZhaoBean
{
private Connection con=null;
public CxpdCanZhaoBean()
{
this.con=DataBaseConnection.getConnection();
}
//操行评定参照是否存在
public boolean existCxpdCanZhao(CxpdCanZhao cxpdCanZhao) {
try {
String referItemId= cxpdCanZhao.getReferItemId();
String itemName= cxpdCanZhao.getItemName();
PreparedStatement pstmt = con.prepareStatement(
"select referItemId from cxpdCanZhao where referItemId='" +referItemId + "' or itemName='"+itemName+"'");
ResultSet rst = pstmt.executeQuery();
if (rst.next()) {
return true;
}
} catch (Exception ex) {
return false;
}
return false;
}
//插入
public String addCxpdCanZhao(CxpdCanZhao cxpdCanZhao)
{
PreparedStatement pstmt=null;
String str="";
try
{
if (existCxpdCanZhao(cxpdCanZhao)) {
return "exist"; //存在此操行评定编号
}
pstmt=con.prepareStatement("insert into CxpdCanZhao values(?,?,?,?)");
pstmt.setString(1,cxpdCanZhao.getReferItemId());
pstmt.setString(2,cxpdCanZhao.getSortId());
pstmt.setString(3,cxpdCanZhao.getItemName());
pstmt.setString(4,cxpdCanZhao.getAdviceScore());
pstmt.execute();
str="sucess";
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//更新
public String updateCxpdCanZhao(CxpdCanZhao cxpdCanZhao)
{
PreparedStatement pstmt=null;
String str="";
try
{
pstmt=con.prepareStatement("update cxpdCanZhao set sortId=?,itemName=?,adviceScore=? where referItemId=?");
pstmt.setString(1,cxpdCanZhao.getSortId());
pstmt.setString(2,cxpdCanZhao.getItemName());
pstmt.setString(3,cxpdCanZhao.getAdviceScore());
pstmt.setString(4,cxpdCanZhao.getReferItemId());
pstmt.execute();
str="sucess";
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//删除
public String deleteCxpdCanZhao(String referItemId)
{
PreparedStatement pstmt=null;
String str="";
try
{
pstmt=con.prepareStatement("delete from cxpdCanZhao where referItemId=?");
pstmt.setString(1,referItemId);
pstmt.execute();
str="sucess";
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//存储过程操行评定
public ResultSet getCxpdCanZhao()
{
ResultSet rst=null;
CallableStatement calStmt=null;
String strSQL="{call pro_cxpdCanZhao}";
try{
calStmt=con.prepareCall(strSQL);
rst=calStmt.executeQuery();
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rst;
}
//查询
public ResultSet executeQuery(String sql)
{
Statement stmt=null;
ResultSet rst=null;
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery(sql);
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rst;
}
//关闭
public void close()
{
try{
if(con!=null){
con.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
//所有操行分类
public String getAllCaoxingFenLei()
{
PreparedStatement pstmt = null;
ResultSet rst = null;
StringBuffer sBuf=new StringBuffer();
try {
pstmt = con.prepareStatement("select distinct sortId,sortName from caoxingFenLei");
rst = pstmt.executeQuery();
while(rst.next()) {
String sortId= rst.getString("sortId");
String sortName= rst.getString("sortName");
sBuf.append("<option value='"+sortId+"'>"+sortName+"</option>\n");
}
}
catch (SQLException ex) {
ex.printStackTrace();
return "";
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return sBuf.toString();
}
//所有班级
public String getAllClass()
{
PreparedStatement pstmt = null;
ResultSet rst = null;
StringBuffer sBuf=new StringBuffer();
try {
pstmt = con.prepareStatement("select distinct classId,className from banji");
rst = pstmt.executeQuery();
while(rst.next()) {
String classId= rst.getString("classId");
String className= rst.getString("className");
sBuf.append("<option value='"+classId+"'>"+className+"</option>\n");
}
}
catch (SQLException ex) {
ex.printStackTrace();
return "";
}
return sBuf.toString();
}
/*
public static void main(String[] args)throws SQLException{
CxpdCanZhaoBean test=new CxpdCanZhaoBean();
ResultSet rst=test.getCxpdCanZhao();
while (rst.next())
{
System.out.println(rst.getString(1));
}
} */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -