Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Desc fetch:java中的n行_Java_Sql_Oracle - Fatal编程技术网

Desc fetch:java中的n行

Desc fetch:java中的n行,java,sql,oracle,Java,Sql,Oracle,我有一个方法包含这样的查询 public List<Order> getOrders (int customer_id, int count) { String sql= "select * from order where customer_id = ? order by order_id DESC FETCH FIRST ? ROWS ONLY" } Missing IN or OUT parameter at index:: 2 如果我删除第二

我有一个方法包含这样的查询

public List<Order> getOrders (int customer_id, int count)
{
  String sql= "select * from order where customer_id = ? order by order_id DESC FETCH FIRST ? ROWS 
  ONLY"
}
Missing IN or OUT parameter at index:: 2

如果我删除第二个?我写了
DESC FETCH前5行
它执行成功。我想我不能在DESC FETCH语句中使用salary参数。你有什么想法吗?

确实
DESC
和中的顺序没有限制

您不能以某种方式设置第二个参数

下面是一个带有标记行的工作JDBC示例,如果注释掉该行,将导致异常

def stmt = con.prepareStatement("""select order_id from getOrders 
                                   where customer_id = ? 
                                   order by order_id DESC
                                   FETCH FIRST ? ROWS ONLY""")
stmt.setInt(1,1001)  /* Bind customer_id = 1001 */
stmt.setInt(2,3)  /* bind count of rows = 3; uncomment to get java.sql.SQLException: Missing IN or OUT parameter at index:: 2  */

def rs = stmt.executeQuery()

while(rs.next())
  {
   println "order_id= ${rs.getInt(1)}"
  }

您能否发布代码的其他部分,因为您发布的函数只是查询,在替换值时您可能缺少一些内容?我使用的是spring Jdbc而不是普通的Jdbc,但我会尝试将您的代码更改为spring Jdbc。非常感谢。您使用的是JDBCTemplate还是spring Data Jdbc?如果您仍然有问题,请发布完整的声明。