No results returned by the Query error in PostgreS

2019-01-18 09:56发布

I am trying to insert a data into a table. After executing the query i am getting an exception stating

org.postgresql.util.PSQLException: No results were returned by the query.
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:284)

The data is getting inserted successfully, but i have no idea why i am getting this exception ??

2条回答
Emotional °昔
2楼-- · 2019-01-18 10:14

Use

executeUpdate

instead of

executeQuery

if no data will be returned (i.e. a non-SELECT operation).

查看更多
干净又极端
3楼-- · 2019-01-18 10:27

If you want last generated id, you can use this code after using executeUpdate() method

 int update = statement.executeUpdate()
 ResultSet rs = statement.getGeneratedKeys();
 if (rs != null && rs.next()) {
  key = rs.getLong(1);
 }
查看更多
登录 后发表回答