This error message is indicating that there are no parameters provided for the SQL query in the PreparedStatementCallback. The error is specifically occurring because the parameter index is out of range, meaning there are no parameters available to be used.

To resolve this issue, make sure that you are correctly setting the parameters for the SQL query. In this case, it seems that you are using named parameters like :values, so you need to set the parameter values using the appropriate method provided by the PreparedStatement class.

Here is an example of how you can set the parameter values using PreparedStatement:

String sql = "SELECT id, un_code FROM t_dept WHERE un_code IN (:values)";
List<String> values = Arrays.asList("value1", "value2", "value3"); // replace with your actual parameter values

PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setArray(1, connection.createArrayOf("VARCHAR", values.toArray()));

// Execute the query and process the results
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
    // Process the row data
    int id = resultSet.getInt("id");
    String unCode = resultSet.getString("un_code");
    // ...
}

In this example, connection is an instance of Connection representing your database connection. values is a list containing the parameter values. The setArray method is used to set the parameter values as an array.

Make sure to adjust the code according to your specific requirements and database setup

PreparedStatementCallback; SQL select idun_code from t_dept where un_code in values; Parameter index out of range 1 number of parameters which is 0; nested exception is javasqlSQLException Parameter

原文地址: https://www.cveoy.top/t/topic/iUjZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录