Search code examples
javapostgresqljdbc

How to resolve No results were returned by the query in PostgreSQL?


I'm trying to change the password of the non-admin user in PostgreSQL using jdbc connection.

statement.executeQuery("ALTER ROLE user1 WITH PASSWORD '6789'");

This above query is throwing:

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

How to resolve this issue?


Solution

  • statement.executeQuery() expects a resultset and you don't get one. Use statement.execute() for an ALTER-statement to avoid this issue.

    Link to the manual: https://jdbc.postgresql.org/documentation/head/ddl.html