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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With