0

I am trying to update a database from eclipse. The database will update, however, the java program will throw a SQLException after the database is updated.

Statement stmnt = null;
    Connection connection = establishConnection();
    stmnt = connection.createStatement();
    stmnt.executeQuery("UPDATE table1  SET column2='"+description+"' WHERE column1='"+id+"'");

this is what is printed in the console:

org.postgresql.util.PSQLException: No results were returned by the query
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Mike
  • 1
  • 1
  • 3
    check this : http://stackoverflow.com/questions/21276059/no-results-returned-by-the-query-error-in-postgresql – Kaustubh Dec 02 '16 at 20:28

1 Answers1

1

executeQuery should be used for statements that return a ResultSet. For other statements, you should use executeUpdate:

stmnt.executeUpdate
    ("UPDATE table1  SET column2='"+description+"' WHERE column1='"+id+"'");

Side note:
Using string manipulation this way may expose your code to SQL injection attacks. You should consider using a PreparedStatement instead.

Mureinik
  • 297,002
  • 52
  • 306
  • 350