简体   繁体   中英

Update query mysql with JDBC

![enter image description here][1]I am trying to update data in table of MySQL database. I am unable to do, since I am beginner so I have no idea how to do , kindly guide me properly. I would be thankful to you..............

Part of cade that generates exception:

        java.sql.PreparedStatement statement = conection.prepareStatement("UPDATE  patient_details set  `Reg_Date`='?', `Name`='?', `Father_Husband_Name`='?', `Address`='?', `City`='?', `Cell_No`='?', `Martial_Status`='?', `Gender`='?', `Status`='?', `Age`='?' where 'Reg_No'='temp'"); 
                    statement.setInt(1, temp); 
                      statement.setString(2,textField_3.getText());
                      statement.setString(3,textField_1.getText());
                      statement.setString(4,textField_2.getText());
                      statement.setString(5,textArea.getText());
                      statement.setString(6,textField_4.getText());
                      statement.setString(7,textField_5.getText());
                      statement.setString(8,(String) comboBox.getSelectedItem()); 
                      statement.setString(9,(String) comboBox_1.getSelectedItem()); 
                      statement.setString(10,(String) comboBox_2.getSelectedItem()); 

                      statement.setInt(11,temp1); 

                      statement.executeUpdate();

Exception is: parameter out of range(1>number of paarameters which is 0)

YOu set 11 parameters but only have 10 ? in the statement. The last part of the statement, the where clause - you have

where 'Reg_No'='temp'" 

which is not a variable. You should be able to drop the statement

  statement.setInt(11,temp1); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM