sqlite-jdbc icon indicating copy to clipboard operation
sqlite-jdbc copied to clipboard

No parameter has been set yet

Open shaohuzhang1 opened this issue 4 months ago • 2 comments

Title: SQLException: No parameter has been set yet when using Vertx JDBC with SQLite

Description:
When executing a parameterized query with vertx-jdbc-client against SQLite, the following exception occurs:

SQLException: No parameter has been set yet

The error originates from the checkIndex method when validating parameter indices.

Stack Trace Snippet:

protected void checkIndex(int index) throws SQLException {
    if (this.batch == null) {
        throw new SQLException("No parameter has been set yet");
    } else if (index < 1 || index > this.batch.length) {
        throw new SQLException("Parameter index is invalid");
    }
}

Dependencies:

<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-web-client</artifactId>
    <version>5.0.3</version>
</dependency>
<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-sql-client-templates</artifactId>
    <version>5.0.3</version>
</dependency>
<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-jdbc-client</artifactId>
    <version>5.0.3</version>
</dependency>
<dependency>
    <groupId>org.xerial</groupId>
    <artifactId>sqlite-jdbc</artifactId>
    <version>3.50.3.0</version>
</dependency>

Reproduction Code:

public class SqliteQuery {
    public static void main(String[] args) {
        String jdbcUrl = "jdbc:sqlite:sqlite.db?journal_mode=WAL&synchronous=NORMAL";
        JDBCConnectOptions connectOptions = new JDBCConnectOptions()
                .setJdbcUrl(jdbcUrl)
                .setAutoGeneratedKeys(false);
        PoolOptions poolOptions = new PoolOptions()
                .setMaxSize(1);
        Pool pool = JDBCPool.pool(Vertx.vertx(), connectOptions, poolOptions);
        SqlTemplate.forQuery(pool, "select * from user where name = #{name}")
                .execute(Map.of("name", "test")).onSuccess(ok -> {
                    System.out.println(ok.stream().iterator().next());
                }).onFailure((e) -> {
                    System.out.println("error");
                });
    }
}

Additional Context:
The issue appears to be specific to SQLite JDBC integration with Vertx parameterized queries. Other databases (e.g., MySQL/PostgreSQL) may not exhibit this behavior.

Environment (please complete the following information):

  • OS: [e.g. Windows 7]
  • CPU architecture: [e.g. x86_64, arm64]
  • sqlite-jdbc version [e.g. 3.39.2.0]

shaohuzhang1 avatar Aug 28 '25 03:08 shaohuzhang1

Could be some incorrect use of JDBC by the library. Maybe other drivers are less strict in that regard. Suggest you open an issue at Vertx JDBC instead, so they can check what is going on.

gotson avatar Aug 28 '25 04:08 gotson

Could be some incorrect use of JDBC by the library. Maybe other drivers are less strict in that regard. Suggest you open an issue at Vertx JDBC instead, so they can check what is going on.

When using SQLite to obtain parameter types, is it necessary to use something like:

public void setxxx(int ​​pos, boolean value) throws SQLException

to set the type of each parameter?

shaohuzhang1 avatar Aug 28 '25 06:08 shaohuzhang1