2016-12-02 120 views
0

我试图更新从日食的数据库。数据库将更新,但是,在更新数据库后,java程序将抛出SQLException。SQL update语句将更新数据库,但会抛出SQL例外

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

这就是被打印到控制台上:

org.postgresql.util.PSQLException: No results were returned by the query 
+3

检查: http://stackoverflow.com/questions/21276059/no-results-returned-by-the-query-error-in-postgresql –

回答

1

executeQuery应该用于返回一个ResultSet语句。对于其他的语句,你应该使用executeUpdate

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

旁注:
使用字符串操作这种方式可能使你的代码,SQL注入攻击。您应该考虑使用PreparedStatement代替。