Skip to content

flight-sql-jdbc-driver throws "parameter ordinal 1 out of range" for PreparedStatement in SELECT query #1009

@eqrvivek

Description

@eqrvivek

Describe the usage question you have. Please include as many useful details as possible.

I am using the flight-sql-jdbc-driver (version 18.x / Doris 3.x) and I am trying to execute a simple SELECT query with a PreparedStatement and a ? placeholder. However, I consistently get the following exception:

java.sql.SQLException: parameter ordinal 1 out of range

Here is the minimal example of the code :

import java.sql.*;

public class DorisTest
{
public static void main(String[] args) throws Exception {
// Connect to Doris Flight SQL
String url = "jdbc:apache:arrow:flight://host:port";
Connection conn = DriverManager.getConnection(url);

    // SQL with a single parameter
    String sql = "SELECT * FROM Connectors WHERE connectorID = ?";
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setInt(1, 1); // This line throws SQLException

    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
        System.out.println(rs.getInt("connectorID"));
    }

    conn.close();
 }

}

The driver throws: java.sql.SQLException: parameter ordinal 1 out of range

Additional observations:

  1. PreparedStatement is obtained directly from the JDBC connection.
  2. PreparedStatement.getParameterMetaData() seems to return 0 parameters.
  3. The driver works fine for queries without placeholders or with inline values.
  4. The Flight SQL JDBC driver appears to not support ? placeholders reliably in this version.

Question:

  1. Is this a known limitation of the Doris Flight SQL JDBC driver?
  2. Are there any workarounds to use PreparedStatement with parameters for SELECT queries?
  3. If placeholders are not supported, what is the recommended way to safely execute parameterized queries (especially for IN clauses with multiple
    values) in Doris Flight SQL JDBC driver?

Any guidance or best practices would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions