Home > Back-end > Use delect the from where to delete not to drop the database content
Use delect the from where to delete not to drop the database content
Time:12-25
Above is I want to delete the specified line database, why can't I speak according to the online method delete repository specified row! (my design is in the window input correct user name and password and then click the logout deleted the user account password) Here is my code Try { Class.forName("com.mysql.jdbc.Driver"); Conn=DriverManager. GetConnection (sql_url, name, password);//connect to the database PreparedStatement ps=null; ResultSet rs=null; PreparedStatement PreparedStatement=null; Int d=0; DefaultTableModel model=(DefaultTableModel) table. The getModel (); for (int i=0; I & lt; Model. GetRowCount (); I++) { Object value2=model. GetValueAt (I, 0). System. The out. Println (value2); The Object value3=model. GetValueAt (I, 1); System. The out. Println (value3); If (textField. GetText () equals (value2)) {
If (passwordField. GetText () equals (value3)) { System.out.println(i); String SQL="DELETE FROM programer WHERE UserName=value2"; //a preparedStatement=conn. ExecuteUpdate (" delete from programer where I "); New prompt2 (); Frame2. RemoveNotify (); break; } The else { JOptionPane pane=new JOptionPane (" password error "); JDialog dialog=pane. CreateDialog (" warning "); Dialog. The show (); } } The else { D++; } } If (d>=model. GetRowCount ()) { JOptionPane pane=new JOptionPane (" the user "); JDialog dialog=pane. CreateDialog (" warning "); Dialog. The show (); }
} The catch (a ClassNotFoundException e1) { //TODO Auto - generated the catch block, E1. PrintStackTrace (); {} the catch (SQLException e1) //TODO Auto - generated the catch block, E1. PrintStackTrace (); }