📄 biyelunwenbean.java
字号:
package biyeLunwen;
import conn.DataBaseConnection;
import java.sql.Date;
import java.sql.*;
import java.util.*;
import java.io.*;
public class BiyeLunwenBean
{
private Connection con=null;
public BiyeLunwenBean()
{
this.con=DataBaseConnection.getConnection();
}
//是否存在学生
public boolean existXuesheng(BiyeLunwen biyeLunwen) {
boolean bool=false;
try {
String studentId = biyeLunwen.getStudentId();
PreparedStatement pstmt = con.prepareStatement(
"select studentId from xuesheng where studentId='" +
studentId + "' and flag='"+1+"'");
ResultSet rst = pstmt.executeQuery();
if (rst.next()) {
bool=true;
}
if(rst!=null){
rst.close();
}
if(pstmt!=null){
pstmt.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return bool;
}
//记录是否存在
public boolean existBiyeLunwen(BiyeLunwen biyeLunwen) {
try {
String studentId = biyeLunwen.getStudentId();
String designTime = biyeLunwen.getDesignTime();
PreparedStatement pstmt = con.prepareStatement(
"select * from biyeLunwen where studentId='" +
studentId + "'");
ResultSet rst = pstmt.executeQuery();
if (rst.next()) {
return true;
}
} catch (Exception ex) {
return false;
}
return false;
}
//插入
public String addBiyeLunwen(BiyeLunwen biyeLunwen)
{
PreparedStatement pstmt=null;
String str="";
try
{
if (!existXuesheng(biyeLunwen)) {
return "notExist"; //不存在此学生
}
if (existBiyeLunwen(biyeLunwen)) {
return "exist"; //此学生计算机等级记录已存在
}
pstmt=con.prepareStatement("insert into biyeLunwen values(?,?,?,?,?,?)");
pstmt.setString(1,biyeLunwen.getStudentId());
pstmt.setString(2,biyeLunwen.getTopical());
pstmt.setString(3,biyeLunwen.getDesignTime());
pstmt.setString(4,biyeLunwen.getScore());
pstmt.setString(5,biyeLunwen.getFjName());
pstmt.setString(6,biyeLunwen.getRemark());
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 updateBiyeLunwen(BiyeLunwen biyeLunwen)
{
PreparedStatement pstmt=null;
String str="";
try
{
pstmt=con.prepareStatement("update biyeLunwen set topical=?,score=?,remark=? where studentId=?");
pstmt.setString(1,biyeLunwen.getTopical());
pstmt.setString(2,biyeLunwen.getScore());
pstmt.setString(3,biyeLunwen.getRemark());
pstmt.setString(4,biyeLunwen.getStudentId());
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 deleteBiyeLunwen(String studentId)
{
PreparedStatement pstmt=null;
String str="";
try
{
pstmt=con.prepareStatement("delete from biyeLunwen where studentId=?");
pstmt.setString(1,studentId);
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 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 getAllClass()
{
Statement stmt = null;
ResultSet rst = null;
StringBuffer sBuf=new StringBuffer();
try {
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery("select distinct classId,className from banji");
while(rst.next()) {
String classId= rst.getString("classId");
String className= rst.getString("className");
sBuf.append("<option value='"+classId+"'>"+className+"</option>\n");
}
}
catch (SQLException ex) {
return "";
}
return sBuf.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -