Preparred Statement错误:ORA-00936:缺少表达式

时间:2015-05-22 17:34:53

标签: java database oracle arraylist prepared-statement

我准备好的陈述有点问题。我收到错误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);

1 个答案:

答案 0 :(得分:4)

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

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