Java Code Examples for com.mysql.jdbc.PreparedStatement#executeUpdate()

The following examples show how to use com.mysql.jdbc.PreparedStatement#executeUpdate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CourseDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int delete_course(String Cno) {
	Connection conn = DBUtils.getConnection();
	String sql = "delete from course where Cno = ?;";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, Cno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 2
Source File: StudentDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int alter_class(String sno, String after_sno,String after_sname,String after_ssex,int after_sage,String after_clno) {
	Connection conn = DBUtils.getConnection();
	String sql = "update student set sno = ?,sname = ?,ssex = ?,sage = ?,clno = ? where sno = ?;";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, after_sno);
		ps.setString(2, after_sname);
		ps.setString(3, after_ssex);
		ps.setInt(4, after_sage);
		ps.setString(5, after_clno);
		ps.setString(6, sno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 3
Source File: StudentDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int delete_student(String sno) {
	Connection conn = DBUtils.getConnection();
	String sql = "delete from student where sno = ?;";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, sno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 4
Source File: StudentDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int insert_student(String Sno,String Sname,String Ssex,int Sage,String Clno) {
	Connection conn = DBUtils.getConnection();
	String sql = "insert into student values(?,?,?,?,?);";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, Sno);
		ps.setString(2, Sname);
		ps.setString(3, Ssex);
		ps.setInt(4, Sage);
		ps.setString(5, Clno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 5
Source File: SCDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int alter_sc(String Sno, String Cno,double after_grade) {
	Connection conn = DBUtils.getConnection();
	String sql = "update sc set grade = ? where sno = ? and cno = ?;";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setDouble(1, after_grade);
		ps.setString(2, Sno);
		ps.setString(3, Cno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 6
Source File: AdminCommand.java    From mapleLemon with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int execute(MapleClient c, String[] splitted) {
    if (splitted.length < 2) {
        c.getPlayer().dropMessage(0, splitted[0] + " <SQL命令>");
        return 0;
    }
    try {
        Connection con = (Connection) DatabaseConnection.getConnection();
        PreparedStatement ps = (PreparedStatement) con.prepareStatement(StringUtil.joinStringFrom(splitted, 1));
        ps.executeUpdate();
        ps.close();
    } catch (SQLException e) {
        c.getPlayer().dropMessage(0, "执行SQL命令失败");
        return 0;
    }
    return 1;
}
 
Example 7
Source File: ClassDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int alter_class(String clno, String after_clno, String after_clname, String after_dno) {
	Connection conn = DBUtils.getConnection();
	String sql = "update class set clno = ?,clname = ?,dno = ? where clno = ?;";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, after_clno);
		ps.setString(2, after_clname);
		ps.setString(3, after_dno);
		ps.setString(4, clno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 8
Source File: ClassDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int delete_class(String clno) {
	Connection conn = DBUtils.getConnection();
	String sql = "delete from class where clno = ?;";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, clno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 9
Source File: ClassDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int insert_class(String clno, String clname, String dno) {
	Connection conn = DBUtils.getConnection();
	String sql = "insert into class values(?,?,?);";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, clno);
		ps.setString(2, clname);
		ps.setString(3, dno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 10
Source File: DepartmentDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int delete_department(String dno) {
	Connection conn = DBUtils.getConnection();
	String sql = "delete from department where dno = ?;";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, dno);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 11
Source File: DepartmentDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int insert_department(String dno,String dname){
	Connection conn = DBUtils.getConnection();
	String sql = "insert into department values(?,?);";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, dno);
		ps.setString(2, dname);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 12
Source File: UserDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int alter_user(String username,String after_username,String after_password,String after_level) {
	Connection conn = DBUtils.getConnection();
	String sql = "update user set username = ?,password = ?,level = ? where username = ?;";
	
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, after_username);
		ps.setString(2, after_password);
		ps.setString(3, after_level);
		ps.setString(4, username);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 13
Source File: UserDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int delete_user(String username) {
	Connection conn = DBUtils.getConnection();
	String sql = "delete from user where username = ?;";
	
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, username);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 14
Source File: UserDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int insert_user(String username,String password,String level){
	Connection conn = DBUtils.getConnection();
	String sql = "insert into user values(?,?,?);";
	
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		
		ps.setString(1, username);
		ps.setString(2, password);
		ps.setString(3, level);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 15
Source File: CourseDao.java    From StudentManagement with MIT License 6 votes vote down vote up
public int insert_course(String Cno, String Cname, String Cteacher, double Ccredit) {
	Connection conn = DBUtils.getConnection();
	String sql = "insert into course values(?,?,?,?);";
	int flag = 0;
	try {
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setString(1, Cno);
		ps.setString(2, Cname);
		ps.setString(3, Cteacher);
		ps.setDouble(4, Ccredit);
		flag = ps.executeUpdate();
		ps.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		DBUtils.closeConnection(conn);
	}
	return flag;
}
 
Example 16
Source File: MeetManagerDaoImpl.java    From scada with MIT License 5 votes vote down vote up
@Override
public void updateAndDelete(int id) {
	
	ActionContext actionContext = ActionContext.getContext();
   	Map<String, Object> session = actionContext.getSession();
   	String select=(String) session.get("select");
   	String message=(String) session.get("message");

   	Connection conn=null;
   	
   	String sql=null;
   	
   	
   	if(!message.equals("")){
   	if(select.equals("id")){
   		try{
   		  			
       		conn=getConnection();
       		     	   
       		sql="UPDATE `scada`.`meet_room` SET `useful`='����' WHERE `meetroom_id`="+"'"+id+"'";

               PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
   		        
       		ps.executeUpdate();
       		    
       	    //MeetManager meetManager=(MeetManager)this.getSessionFactory().openSession().get(MeetManager.class, id);
       		//this.getHibernateTemplate().delete(meetManager);
       		//this.getSessionFactory().openSession().close();
       		conn.close();
       		conn=null;
       		System.out.println(conn);
       		
   		}catch(Exception e){
   			System.out.println(e);		
   	     }
   	}
   		
   }
  }
 
Example 17
Source File: MeetManagerDaoImpl.java    From scada with MIT License 4 votes vote down vote up
@Override
public void save() {
	
	Connection conn=null;
	try {  
		ActionContext actionContext = ActionContext.getContext();
    	Map<String, Object> session = actionContext.getSession();

    	String []file=new String[10];

    	/*****************************************************/
		file[0]=(String) session.get("meet_id");
		file[1]=(String) session.get("meet_name");
		file[2]=(String) session.get("meet_title");
		file[3]=(String) session.get("meet_content");
		file[4]=(String) session.get("people_num");		
		file[5]=(String) session.get("start_end");
		file[6]=(String) session.get("location");
		file[7]=(String) session.get("meetroom_num");			
		file[8]=(String) session.get("useful_time");
		file[9]=(String) session.get("room_size");
		int meet_id=Integer.valueOf(file[0]);
		int people_num=Integer.valueOf(file[4]);
		int meetroom_num=Integer.valueOf(file[7]);
		int room_size=Integer.valueOf(file[9]);
		/*****************************************************/

		conn=getConnection();

		String sql=
           "INSERT INTO `scada`.`meet_manager` (`meet_id`, `meet_name`, `meet_title`, `meet_content`, `people_num`, `start_end`, `location`, `meetroom_num`, `useful_time`, `room_size`) "
		+ "VALUES ("+"'"+meet_id+"', '"+file[1]+"', '"+file[2]+"', '"+file[3]+"', '"+people_num+"', '"+file[5]+"', '"+file[6]+"', '"+meetroom_num+"', '"+file[8]+"', '"+room_size+"');";
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		int row = ps.executeUpdate();  
           
           if(row > 0) 
                  System.out.println("�ɹ������" + row + "������"); 
           
		
		conn.close();
		conn=null;
		
	}catch(Exception e){
		e.printStackTrace();
	}
	
}
 
Example 18
Source File: FileManagerDaoImpl.java    From scada with MIT License 4 votes vote down vote up
@Override
public void save() {
	
	try {  
		ActionContext actionContext = ActionContext.getContext();
    	Map<String, Object> session = actionContext.getSession();
    	int j = 1;

    	String []file=new String[20];
		file[0]=(String) session.get("sname");
		file[1]=(String) session.get("identity_card");
		file[2]=(String) session.get("sex");
		file[3]=(String) session.get("both");
		file[4]=(String) session.get("age");
		
		file[5]=(String) session.get("location");
		file[6]=(String) session.get("zip_code");
		file[7]=(String) session.get("nation");
		
		file[8]=(String) session.get("politics_status");
		file[9]=(String) session.get("school");
		file[10]=(String) session.get("education_background");
		file[11]=(String) session.get("major");
		
		
		file[12]=(String) session.get("job_title");
		file[13]=(String) session.get("job_title_date");
		file[14]=(String) session.get("qualification");
		file[15]=(String) session.get("telephone");
		file[16]=(String) session.get("mobilephone");
		file[17]=(String) session.get("urgent_phone");
		file[18]=(String) session.get("company_email");
		file[19]=(String) session.get("sole_email");
		int age=Integer.valueOf(file[4]);

           Class.forName("com.mysql.jdbc.Driver");  

           String url = "jdbc:mysql://localhost:3306/scada";  

           String username = "root";  

           String password = "root";  

           Connection conn = (Connection) DriverManager.getConnection(url , username , password); 
           if (conn != null)   
           	  
               System.out.println("���ݿ����ӳɹ�!");  

           else  

               System.out.println("���ݿ�����ʧ��!");  

           //��ɺ�ǵùر����ݿ�����      
       
           String sql_1="SELECT `sid` FROM `scada`.`file_manager`;";
           PreparedStatement ps_1 = (PreparedStatement) conn.prepareStatement(sql_1);
           ResultSet s_1=ps_1.executeQuery();
           int sid;
             while(s_1.next()){
                 sid =s_1.getInt(1);
                 System.out.println(sid);
		      if(sid==0)
                 {
		    	  System.out.println(sid);
                 }else
               	 j=sid+1;
               }

           /*String sql_2="SELECT `identity_card` FROM `big_project`.`file_manager` WHERE identity_card="+"'"+file[1]+"';";
           PreparedStatement ps_2 = (PreparedStatement) conn.prepareStatement(sql_2);
           ResultSet s_2=ps_2.executeQuery();
           System.out.println(6);
           if(s_2==null){
           	System.out.println(7);*/
           String sql=
           		"INSERT INTO `scada`.`file_manager` (`sid`, `sname`, `identity_card`, `sex`, `both`, `age`, `location`, `zip_code`, `nation`, `politics_status`, `school`, `education_background`, `major`, `job_title`, `job_title_date`, `qualification`, `telephone`, `mobilephone`, `urgent_phone`, `company_email`, `sole_email`) "
           		+ "VALUES ('"+j+"', "+"'"+file[0]+"', '"+file[1]+"', '"+file[2]+"', '"+file[3]+"', '"+age+"', '"+file[5]+"', '"+file[6]+"', '"+file[7]+"', '"+file[8]+"', '"+file[9]+"', '"+file[10]+"', '"+file[11]+"', '"+file[12]+"', '"+file[13]+"', '"+file[14]+"', '"+file[15]+"', '"+file[16]+"', '"+file[17]+"', '"+file[18]+"', '"+file[19]+"');";
           PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
           
           int row = ps.executeUpdate();  
          
           if(row > 0) 
                  System.out.println("�ɹ������" + row + "������"); 
           //}else{
           conn.close();
           conn=null;
           //} 
	}catch(Exception e){
		System.out.println(e);
	}
}
 
Example 19
Source File: MeetManagerDaoImpl.java    From scada with MIT License 3 votes vote down vote up
@Override
public void updateAndInput(int id){

   	Connection conn=null;
   	
   	String sql=null;
   
   	
   		try{
   				
       		conn=getConnection();
       	    
       		sql="UPDATE `scada`.`meet_room` SET `useful`='������' WHERE `meetroom_id`="+"'"+id+"'";

               PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
   		        
       		ps.executeUpdate();
       		    
       	    //MeetManager meetManager=(MeetManager)this.getSessionFactory().openSession().get(MeetManager.class, id);
       		//this.getHibernateTemplate().delete(meetManager);
       		//this.getSessionFactory().openSession().close();
       		conn.close();
       		conn=null;
       		
       		
   		}catch(Exception e){
   			System.out.println(e);		
   	    }
   
}
 
Example 20
Source File: AchievementDaoImpl.java    From scada with MIT License 2 votes vote down vote up
@Override
public void save() {
	ActionContext actionContext = ActionContext.getContext();
   	Map<String, Object> session = actionContext.getSession();
   	String infor=(String) session.get("information");
 
	try{   	  	

       Class.forName("com.mysql.jdbc.Driver");  

       String url = "jdbc:mysql://localhost:3306/scada";  

       String username = "root";  

       String password = "root";  

       Connection conn = (Connection) DriverManager.getConnection(url , username , password); 
       
       if (conn != null)   
     	  
           System.out.println("���ݿ����ӳɹ�!");  

       else  

           System.out.println("���ݿ�����ʧ��!"); 
       
       String sql_1="SELECT `id` FROM `scada`.`information`;";
       PreparedStatement ps_1 = (PreparedStatement) conn.prepareStatement(sql_1);
       ResultSet s_1= ps_1.executeQuery();
       
       int id=0;
         while(s_1.next()){
             id =s_1.getInt("id");
           }
           int id_1=id+1;    

       String sql_2="INSERT INTO `scada`.`information` (`id`,`text`) VALUES ('"+id_1+"','"+infor+"')";
       
       
       PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql_2);
       
       int row = ps.executeUpdate(); 
       
       if(row > 0) 
           System.out.println("�ɹ������" + row + "������"); 

 
    	
       conn.close();
       conn=null;
	}catch(Exception e){
		e.printStackTrace();
	}
}