Skip to content

Executing a PreparedStatement after creating a secret (or after reading the secrets) fails with Binder Error: Parameter/argument count mismatch for prepared statement. Expected 0, got 1 #294

@maartenbosteels

Description

@maartenbosteels

This code fails:

    @Test
    public void setVariable_v3() throws SQLException {
        // this fails
        Connection conn = DriverManager.getConnection("jdbc:duckdb:");
        conn.createStatement().execute("CREATE or replace PERSISTENT SECRET (TYPE postgres, HOST 'localhost', database 'anything', user 'anyone', password 'youchoose')");
        PreparedStatement preparedStatement = conn.prepareStatement("set variable my_var = ?");
        preparedStatement.setString(1, "my value");
        preparedStatement.execute();
    }

with:

java.sql.SQLException: Binder Error: Parameter/argument count mismatch for prepared statement. Expected 0, got 1

	at org.duckdb.DuckDBNative.duckdb_jdbc_execute(Native Method)
	at org.duckdb.DuckDBPreparedStatement.execute(DuckDBPreparedStatement.java:193)
	at org.duckdb.DuckDBPreparedStatement.execute(DuckDBPreparedStatement.java:159)
	at eu.bosteels.DuckDbTest.setVariable_v3(DuckDbTest.java:137)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)

Reading the secrets also causes the preparedStatement.execute() to fail:

    @Test
    public void readSecretsAndSetVariable() throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:duckdb:");
        Statement stmt = conn.createStatement();
        stmt.executeQuery("SELECT * FROM duckdb_secrets()");
        PreparedStatement preparedStatement = conn.prepareStatement("set variable my_var = ?");
        preparedStatement.setString(1, "my value");
        preparedStatement.execute();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions