Reputation: 65
I have problem with my SQL request, when I run my request, I receive this message error:
org.postgresql.util.PSQLException: A result was returned when none was expected.
Here is my request:
Connexion con = new Connexion();
try {
c = con.Connect();
stmt = c.createStatement();
int sqlCalcul = stmt.executeUpdate(
"SELECT inventaire FROM calcul WHERE designation='" + designation +
"' AND date=(SELECT MAX(date) FROM calcul)");
stmt.close();
// c.commit();
c.close();
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("Records created successfully");
Upvotes: 0
Views: 361
Reputation: 12116
You should use executeQuery
instead of executeUpdate
:
ResultSet sqlCalcul = stmt.executeQuery("SELECT inventaire...")
executeUpdate
is used for a INSERT
, UPDATE
, or DELETE
statement, and will throw an exception if a ResultSet
is returned. executeQuery
should be used for SELECT
statements.
Take a look at PostgreSQL's tutorial using the JDBC driver for more information.
Upvotes: 2