This error message indicates that no parameters were provided for the SQL query within the 'PreparedStatementCallback'. The error arises because the parameter index is out of range, meaning no parameters are available for use.

To resolve this, ensure that you are setting the parameters for the SQL query correctly. In this instance, you're employing named parameters like ':values', so you need to set the parameter values using the appropriate method provided by the 'PreparedStatement' class.

Here's an example of how to set 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' represents an instance of 'Connection' for your database connection. 'values' is a list containing the parameter values. The 'setArray' method sets the parameter values as an array.

Remember to adapt the code based on your specific requirements and database configuration.

PreparedStatementCallback: Parameter Index Out of Range Error in SQL with Named Parameters

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

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