Note that there are some explanatory texts on larger screens.

plurals
  1. POjava mysql executeupdate update
    primarykey
    data
    text
    <p>i tried writing a code, that would update a record when a button is pressed with any changes made to any fields. it displays an error message though. this is the code:</p> <pre><code> 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); </code></pre> <p>The connection to the db and stuff all works, so it must be just the syntax, as this is the error message i am getting:</p> <pre><code>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) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload