Prepared message error: ORA-00936: missing expression
I have a little problem with my prepared statement. I got error ORA-00936: Missing expression on execution executeQuery()
. Can you tell me what I missed?
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;
}
}
Method call
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);
+3
source to share
1 answer
date
is a reserved keyword in many RDBMS, including Oracle, where you should avoid it with double quotes "
(which must also be escaped with \
in case the string is created with double quotes):
reachOperation = connection.prepareStatement("SELECT * FROM operations WHERE
account_id = ? AND (\"date\" BETWEEN ? AND ?)");
+4
source to share