2012-03-06 18 views
0

フィールドを変更してボタンを押したときにレコードを更新するコードを書きました。それはしかし、エラーメッセージを表示します。これは私が取得していますエラーメッセージであるとして、それは、単なる構文でなければならないので、java mysql executeupdate update

JButton button = new JButton("Save"); 
    button.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent arg0) {   

     try { 
      con.stmt.executeUpdate("UPDATE student set (StudentID=" + txtAUniqueStudent.getText() + ", FirstName=" + textField_1.getText() + ", Surname=" + textField_2.getText() + ", DOB=" + textField_3.getText() + ", Gender=" + textField.getText() + ", AddressLine1=" + textField_4.getText() + ", AddressLine2=" + textField_5.getText() + ", PostCode=" + textField_6.getText() + ", FatherFullName=" + textField_7.getText() + ", Phone" + textField_8.getText() + ", Mobile=" + textField_9.getText() + ", Fax=" + textField_10.getText() + ", Email=" + textField_11.getText() + ", EmergencyContactName=" + textField_12.getText() + ", EmergencyTel=" + textField_13.getText() + ", AcademicYear=" + textField_14.getText() + ", Subjects=" + textField_15.getText() + "WHERE studentID =" + textField_16.getText()); 
      con.stmt.executeUpdate(); 
      JOptionPane.showMessageDialog(frmFindStudent, "Record has been updated successfully."); 
     } 

     catch (SQLException e) { 
     //System.out.println("Record couldn't be added!"); 
     e.printStackTrace(); 
     JOptionPane.showMessageDialog(frmFindStudent, "Record couldn't be updated. Please try again."); 
     } 
     } 
     }); 
    button.setBounds(333, 517, 89, 23); 
    panel_1.add(button); 

デシベルとスタッフへの接続すべての作品:これはコードです

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(StudentID=25415, FirstName=Shangeethan, Surname=Seevaratnam, DOB=30.08.1994, Ge' at line 1 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
at java.lang.reflect.Constructor.newInstance(Unknown Source) 
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
at com.mysql.jdbc.Util.getInstance(Util.java:386) 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) 
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) 
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) 
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618) 
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1749) 
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1666) 
at FindStudent$2.actionPerformed(FindStudent.java:255) 
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
at java.awt.Component.processMouseEvent(Unknown Source) 
at javax.swing.JComponent.processMouseEvent(Unknown Source) 
at java.awt.Component.processEvent(Unknown Source) 
at java.awt.Container.processEvent(Unknown Source) 
at java.awt.Component.dispatchEventImpl(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Window.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
at java.awt.EventQueue.access$000(Unknown Source) 
at java.awt.EventQueue$1.run(Unknown Source) 
at java.awt.EventQueue$1.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) 
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue$2.run(Unknown Source) 
at java.awt.EventQueue$2.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue.dispatchEvent(Unknown Source) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.run(Unknown Source) 

答えて

2

あなたがエラーを持っています

", Phone" + textField_8.getText() 

はまた、あなたが閉じずに(開く、そして実際にあなたがそれを必要といけない:

set (StudentID 
0123ここで、あなたは=記号を忘れてしまいましたあなたは、String.Formatのを使用し、より読みやすく、簡単にエラーを検出することができ

con.stmt.executeUpdate("UPDATE student set StudentID='" + txtAUniqueStudent.getText() + "', FirstName='" + textField_1.getText() + "', Surname='" + textField_2.getText() + "', DOB='" + textField_3.getText() + "', Gender='" + textField.getText() + "', AddressLine1='" + textField_4.getText() + "', AddressLine2='" + textField_5.getText() + "', PostCode='" + textField_6.getText() + "', FatherFullName='" + textField_7.getText() + "', Phone='" + textField_8.getText() + "', Mobile='" + textField_9.getText() + "', Fax='" + textField_10.getText() + "', Email='" + textField_11.getText() + "', EmergencyContactName='" + textField_12.getText() + "', EmergencyTel='" + textField_13.getText() + "', AcademicYear='" + textField_14.getText() + "', Subjects='" + textField_15.getText() + "' WHERE studentID ='" + textField_16.getText()) + "'"; 

あなたのようなスペースで名前が存在する場合には、引用符の「name」の間に文字列を配置する必要があり

String statement = String.format("UPDATE student set studentId='%s', firstName='%s'", 
id, name); 
+0

それでも構文が間違っているというエラーメッセージが表示される –