gpt4 book ai didi

java - 准备好的语句错误 : ORA-00936: missing expression

转载 作者:搜寻专家 更新时间:2023-10-30 19:43:03 26 4
gpt4 key购买 nike

我准备好的声明有点问题。我收到错误 ORA-00936:执行 executeQuery() 时缺少表达式。你能告诉我我错过了什么吗?

在我的类构造函数中。

private PreparedStatement reachOperation;
reachOperation = connection.prepareStatement("SELECT * FROM operations WHERE account_id = ? AND (date BETWEEN ? AND ?)");

我的方法。

  public List<Operation> getOperations(int number, Date from, Date to)
throws DataStoreException {

ArrayList <Operation> result = new ArrayList<Operation>();

try {

java.sql.Date debut = new java.sql.Date(from.getTime());
java.sql.Date fin = new java.sql.Date(to.getTime());


reachOperation.setInt(1,number);
reachOperation.setDate(2,debut);
reachOperation.setDate(3,fin);


ResultSet rs = reachOperation.executeQuery();
while(rs.next()){

result.add(new Operation(rs.getInt(2),rs.getDouble(3),rs.getDate(4)));

}
rs.close();
return result;

} catch (SQLException error) {
error.printStackTrace();
return result;
}

}

方法的调用

    List<Operation>operations = new ArrayList<>();
operations = manager.getOperations(1, minDate, maxDate);

// check just do prinln depending of the result of the boolean expression
check("Blahblahblah", operations != null && operations.size() == 1);
System.out.println("orders = " + operations);

最佳答案

date 是许多 RDBMS(包括 Oracle)中的保留关键字,您应该使用双引号将其转义 "(也应使用 \ 如果字符串是用双引号创建的):

reachOperation = connection.prepareStatement("SELECT * FROM operations WHERE
account_id = ? AND (\"date\" BETWEEN ? AND ?)");

关于java - 准备好的语句错误 : ORA-00936: missing expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30402712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com