I recently upgraded from sqlite-jdbc-3.7.2.jar to sqlite-jdbc-3.26.0.jar. I observed that the insert query in my code are failing with “java.sql.SQLException: Values not bound to statement” exception.
Below is the piece of code which works fine for previous version of sqlite :
String sqlStatement = "INSERT INTO table_name(id,name,type,author,size) VALUES (?,?,?,?,?)";
try
{
Connection conn = this.connect(<name>);
PreparedStatement pstmt = conn.prepareStatement(sqlStatement))
{
pstmt.setInt(1, rs.getInt(<value>));
pstmt.setString(2, rs.getString(<value>));
pstmt.setInt(3, rs.getInt(<value>));
if (somecondition)
{
pstmt.setString(4, rs.getString(<Value>));
pstmt.setInt(5, rs.getInt(<value>));
}
pstmt.executeUpdate();
}
}
catch(Exception e)
{
//handling of exception goes here
}
I have read the release notes https://www.sqlite.org/changes.html and checked that as a part of Query planner enhancements, few things were changed (The query planner examines the values of bound parameters to help determine if a partial index is usable. ). But I am still not clear what was the enhancement and how it is affecting my code. Also can someone guide me on how to fix the above code?
Thanks, Ketaki
someconditionis false, you only supply 3. This is what SQLite complains about.PreparedStatement pstmt = conn.prepareStatement(sqlStatement))you have an extra right parenthesis and right below you have a block surrounded with curly brackets, why? Is there an if statement that is missing and not allowing the parameters to get values? Anyway, you do have later such an if statement.