⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lunwenketibean.java

📁 JSP开发的学生信息管理系统
💻 JAVA
字号:
package biyeLunwen;
import conn.DataBaseConnection;
import java.sql.Date;
import java.sql.*;
import java.util.*;
import java.io.*;
public class LunwenKeTiBean
{
	private Connection con=null;
	public LunwenKeTiBean()
	{
		this.con=DataBaseConnection.getConnection();
	}
	
	//是否存在论文课题编号
	public boolean existLunwenKeTi(LunwenKeTi lunwenKeTi) {
        boolean bool=false;
        try {
            String topicId = lunwenKeTi.getTopicId();
            PreparedStatement pstmt = con.prepareStatement(
                    "select studentId from LunwenKeTi where topicId='" +
                    topicId + "'");
            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 addLunwenKeTi(LunwenKeTi lunwenKeTi)
	{
		PreparedStatement pstmt=null;
		String str="";
		try
		{
            if (existLunwenKeTi(lunwenKeTi)) {
                return "exist"; //此论文课题记录已存在
            }
			pstmt=con.prepareStatement("insert into lunwenKeTi values(?,?,?,?,?,?)");
			pstmt.setString(1,lunwenKeTi.getTopicId());
			pstmt.setString(2,lunwenKeTi.getGrade());
			pstmt.setString(3,lunwenKeTi.getTopical());
			pstmt.setString(4,lunwenKeTi.getLeaderTeacher());
			pstmt.setString(5,lunwenKeTi.getKaifaYuyan());
			pstmt.setString(6,lunwenKeTi.getXuanTiRenShu());
			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 updateLunwenKeTi(LunwenKeTi lunwenKeTi)
	{
		PreparedStatement pstmt=null;
		String str="";
		try
		{
			pstmt=con.prepareStatement("update lunwenKeTi set grade=?,topical=?,leaderTeacher=?,kaifaYuyan=?,xuanTiRenShu=? where topicId=?");			
			pstmt.setString(1,lunwenKeTi.getGrade());
			pstmt.setString(2,lunwenKeTi.getTopical());
			pstmt.setString(3,lunwenKeTi.getLeaderTeacher());
			pstmt.setString(4,lunwenKeTi.getKaifaYuyan());
			pstmt.setString(5,lunwenKeTi.getXuanTiRenShu());
			pstmt.setString(6,lunwenKeTi.getTopicId());
			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 deleteLunwenKeTi(String topicId)
	{
		PreparedStatement pstmt=null;
		String str="";
		try
		{
			pstmt=con.prepareStatement("delete from lunwenKeTi where topicId=?"); 
			pstmt.setString(1,topicId);
			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 className from banji");
      while(rst.next()) { 
        String className= rst.getString("className");
        sBuf.append("<option value='"+className+"'>"+className+"</option>\n");
        }
    }
    catch (SQLException ex) {
      return "";
    }
    return sBuf.toString();
  }
     
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -