Jefferey Cave
Jefferey Cave

Reputation: 2899

simple query: not implemented by SQLite JDBC driver

First crack at using SQLite+Java and I'm recieving an error when I attempt to execute a simple simple query.

Error: not implemented by SQLite JDBC driver

Query:

String sql = 
    "select Asset, Qty*Price+Fees as Cost \n" +
    "from   Transactions t \n" +
    "       inner join TransactionItems i on t.Id = i.TransactionId \n" +
    "where  TransDate <= ? \n";

try (PreparedStatement stmt = cnn.prepareStatement(sql)) {
    java.sql.Date dte = new java.sql.Date(SumDate().getTimeInMillis());
    stmt.setDate(1, dte);

    try(ResultSet rs = stmt.executeQuery(sql)) {
        while(rs.next()) {
            PortfolioSummaryItem item = new PortfolioSummaryItem(PortfolioSummary.this);
            item.Load(rs);
            items.put(item.asset,item);
        }
        rs.close();
    }

    stmt.close();

Upvotes: 15

Views: 15472

Answers (2)

Jefferey Cave
Jefferey Cave

Reputation: 2899

This was a simple cut/paste style error. When using prepared statements, you shouldn't then pass the SQL into the executeQuery.

Change:

try(ResultSet rs = stmt.executeQuery(sql)){

To:

try(ResultSet rs = stmt.executeQuery()){

This was overriding the preparedStatement.

What it was complaining about was executing a query with a '?' in it since it wasn't the prepared query.

Upvotes: 41

Amy A
Amy A

Reputation: 131

Check the jdbc driver you have in the libs folder. It looks like it has not implemented the methods you have called.

Try downloading the driver from here: https://bitbucket.org/xerial/sqlite-jdbc/downloads

Upvotes: 0

Related Questions