I have a little problem with my prepared statement. I got error ORA-00936: missing expression when doing executeQuery()
. Can you tell me what i missed ?
我准备好的陈述有点问题。我收到错误ORA-00936:执行executeQuery()时缺少表达式。你能告诉我我错过了什么吗?
In my class constructor.
在我的类构造函数中。
private PreparedStatement reachOperation;
reachOperation = connection.prepareStatement("SELECT * FROM operations WHERE account_id = ? AND (date BETWEEN ? AND ?)");
My method.
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;
}
}
Call of method
调用方法
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);
1 个解决方案
#1
4
date
is a reserved keyword in many RDBMS including Oracle, where you should escape it with double quotes "
(which should also be escaped with \
in case string is created with double quotes):
date是许多RDBMS中的保留关键字,包括Oracle,您应该使用双引号将其转义为“(如果使用双引号创建字符串,也应该使用\来转义):
reachOperation = connection.prepareStatement("SELECT * FROM operations WHERE
account_id = ? AND (\"date\" BETWEEN ? AND ?)");
#1
4
date
is a reserved keyword in many RDBMS including Oracle, where you should escape it with double quotes "
(which should also be escaped with \
in case string is created with double quotes):
date是许多RDBMS中的保留关键字,包括Oracle,您应该使用双引号将其转义为“(如果使用双引号创建字符串,也应该使用\来转义):
reachOperation = connection.prepareStatement("SELECT * FROM operations WHERE
account_id = ? AND (\"date\" BETWEEN ? AND ?)");