Java 尝试执行SELECT查询时引发PSQLException

Java 尝试执行SELECT查询时引发PSQLException,java,sql,jdbc,Java,Sql,Jdbc,我的SQL请求有问题,当我运行请求时,我收到以下消息错误: org.postgresql.util.PSQLException: A result was returned when none was expected. 这是我的要求: Connexion con = new Connexion(); try { c = con.Connect(); stmt = c.createStatement(); int sqlCalcul = stmt.executeUpdate

我的SQL请求有问题,当我运行请求时,我收到以下消息错误:

org.postgresql.util.PSQLException: A result was returned when none was expected.
这是我的要求:

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");

您应该使用
executeQuery
而不是
executeUpdate

ResultSet sqlCalcul = stmt.executeQuery("SELECT inventaire...")
用于
插入
更新
删除
语句,如果返回
结果集
,将引发异常。应用于
SELECT
语句

有关更多信息,请查看使用JDBC驱动程序