📄 jiangchengbean.java
字号:
package jiangcheng;
import conn.DataBaseConnection;
import java.sql.Date;
import java.sql.*;
import java.util.*;
import java.io.*;
public class JiangchengBean
{
private Connection con=null;
public JiangchengBean()
{
this.con=DataBaseConnection.getConnection();
}
//是否存在
public boolean existXuesheng(Jiangcheng jiangcheng) {
boolean bool=false;
try {
String studentId = jiangcheng.getStudentId();
PreparedStatement pstmt = con.prepareStatement(
"select * 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 String addJiangcheng(Jiangcheng jiangcheng)
{
PreparedStatement pstmt=null;
String str="";
try
{
if (!existXuesheng(jiangcheng)) {
return "notExist"; //不存在此学生
}
pstmt=con.prepareStatement("insert into jiangcheng(jiangchengName,studentId,jiangchengDate,jiangchengType,jiangchengDescript) values(?,?,?,?,?)");
pstmt.setString(1,jiangcheng.getJiangchengName());
pstmt.setString(2,jiangcheng.getStudentId());
pstmt.setString(3,jiangcheng.getJiangchengDate());
pstmt.setString(4,jiangcheng.getJiangchengType());
pstmt.setString(5,jiangcheng.getJiangchengDescript());
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 updateJiangcheng(Jiangcheng jiangcheng)
{
PreparedStatement pstmt=null;
String str="";
try
{
pstmt=con.prepareStatement("update jiangcheng set jiangchengName=?,jiangchengDate=?,jiangchengType=?,jiangchengDescript=? where jiangchengId=?");
pstmt.setString(1,jiangcheng.getJiangchengName());
pstmt.setString(2,jiangcheng.getJiangchengDate());
pstmt.setString(3,jiangcheng.getJiangchengType());
pstmt.setString(4,jiangcheng.getJiangchengDescript());
pstmt.setString(5,jiangcheng.getJiangchengId());
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 deleteJiangcheng(int jiangchengId)
{
PreparedStatement pstmt=null;
String str="";
try
{
pstmt=con.prepareStatement("delete from jiangcheng where jiangchengId=?");
pstmt.setInt(1,jiangchengId);
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();
}
/*
public static void main(String[] args)throws Exception
{
JiangliBean jiangliBean=new JiangliBean();
Jiangli jiangli=new Jiangli();
jiangli.setJiangliName("dsdf");
jiangli.setStudentId("0368110045");
jiangli.setJiangliDate("2005-09-08");
jiangli.setJiangliType("国家级");
jiangli.setJiangliDescript("dsfdsfdsfdsf");
String str=jiangliBean.addJiangli(jiangli);
System.out.println(str);
} */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -