This is the dependency I'm testing with.
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>flight-sql-jdbc-driver</artifactId>
<version>13.0.0</version>
</dependency>
public static void handleSqlStatements() throws SQLException {
String url = "jdbc:arrow-flight://localhost:5000;useEncryption=false;";
var connection = DriverManager.getConnection(url);
String sql = "select * from SometypeDB.`Table` where OID = ?";
System.out.println("SQL query: " + sql);
try (Connection conn = DriverManager.getConnection(url);
PreparedStatement statement = conn.prepareStatement(sql)) {
int parameterIndex = 1;
long value = 123L;
System.out.println("Setting parameter at index " + parameterIndex + " to value " + value);
statement.setLong(parameterIndex, value);
System.out.println("Executing SQL query: " + sql);
try (ResultSet rs = statement.executeQuery()) {
}// Process ResultSet
} catch (SQLException e) {
e.printStackTrace(); // Ensure detailed error output is available
}
}
This is the error I get when I'm running the code:
SQL query: select * from SometypeDB.`Table` where OID = ?
Setting parameter at index 1 to value 123
java.sql.SQLException: parameter ordinal 1 out of range
at cfjd.org.apache.calcite.avatica.Helper.createException(Helper.java:60)
at cfjd.org.apache.calcite.avatica.AvaticaPreparedStatement.getParameter(AvaticaPreparedStatement.java:427)
at cfjd.org.apache.calcite.avatica.AvaticaPreparedStatement.getSite(AvaticaPreparedStatement.java:434)
at cfjd.org.apache.calcite.avatica.AvaticaPreparedStatement.setLong(AvaticaPreparedStatement.java:178)
Adding the part in the code that throws the exception:
protected AvaticaParameter getParameter(int param) throws SQLException {
try {
return (AvaticaParameter)this.getSignature().parameters.get(param - 1);
} catch (IndexOutOfBoundsException var3) {
throw AvaticaConnection.HELPER.toSQLException(AvaticaConnection.HELPER.createException("parameter ordinal " + param + " out of range"));
}
}`