Am I missing something obvious here?
I have the following method to execute queries against an SQLite local database using org.xerial:sqlite-jdbc:3.21.0.
public List<HashMap<String, Object>> executeQuery(String sql, List<Object> vals) throws Exception {
List<HashMap<String, Object>> rows = new ArrayList<>();
Connection conn = getConnection();
try (PreparedStatement stmnt = conn.prepareStatement(sql)) {
if (!vals.isEmpty()) {
for (int i = 0; i < vals.size(); i++) {
stmnt.setObject(i + 1, vals.get(i));
}
}
ResultSet rs = stmnt.executeQuery();
ResultSetMetaData meta = rs.getMetaData();
HashMap<String, Object> row;
while (rs.next()) {
row = new HashMap<>();
for (int i = 0; i < meta.getColumnCount(); i++) {
row.put(meta.getColumnName(i + 1), rs.getObject(i + 1));
}
rows.add(row);
}
} finally {
putConnection(conn);
}
return rows;
}
However, when I pass the following SQL into the method along with the following values, they don't get set (but it also doesn't throw an exception). It's like it internally assigns it but forgets to tell the database.
SELECT * FROM 'airlines' WHERE 'name' LIKE ? LIMIT 1
vals: size = 1 {"MyAirline"}
I can see from debugging that it gets inside the loop to setObject.
