1

I have problem with my Programs . Help me please.

java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

Class.forName("com.mysql.jdbc.Driver");
String path = "jdbc:mysql://localhost:3306/sampledb";
String Username = "root";
String Password = ""; 
Connection con = DriverManager.getConnection(path, Username, Password);
Statement s = con.createStatement();

String rGanTz = "UPDATE info SET Firstname = '"+txt_Firstname.getText()+"', Lastname = '"+txt_Lastname.getText()+"', Contact = '"+txt_Contact.getText()+"', WHERE '"+txt_Edpno.getText()+"'=EDPNO";
s.executeQuery(rGanTz);

JOptionPane.showMessageDialog(null,"Data has been successfully Updated","Update file", JOptionPane.INFORMATION_MESSAGE,null);
3
  • 2
    For UPDATE statement use executeUpdate instead of executeQuery Commented Nov 5, 2014 at 13:08
  • 2
    Grumble. It's 2014. It's been the year of the cybercriminal every year now since about 2006. Why do people still write sql-injectable code? Please consider using prepared statements and bind parameters. Commented Nov 5, 2014 at 13:21
  • What's unclear about the error message? Commented Nov 6, 2014 at 8:28

1 Answer 1

3

You should really consider what @OllieJones says in the comments about using prepared statements. @Rimas already gave you the solution so I will simply provide an example:

Connection con = DriverManager.getConnection(path, Username, Password);

String rGanTz = "UPDATE info SET Firstname = ?, Lastname = ?, Contact = ? " + 
                "WHERE EDPNO = ?";

PreparedStatement ps = con.prepareStatement(rGanTz);
ps.setString(1, txt_Firstname.getText());
ps.setString(2, txt_Lastname.getText());
ps.setString(3, txt_Contact.getText());
ps.setString(4, txt_Edpno.getText());

ps.executeUpdate();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.