1. Taro L. Saito
  2. sqlite-jdbc
  3. Issues
Issue #36 resolved

Calling PreparedStatement.clearParameters() after a ResultSet is opened, causes subsequent calls to the ResultSet to return null

Anonymous created an issue

I have a prepared statement where I select a single column from a table. The column I want is an INTEGER PRIMARY KEY AUTOINCREMENT column. every such query of mine is returning a null object in the JDBC result set.

I have linked relevant peices of my code below...

this is where ive been testing Prepared statment creation Table creation

if I hardcode the query to...

SELECT groupID FROM groups WHERE groupName="someGroup"

it works fine... the moment I use a prepared statement with a palceholder...

SELECT groupID FROM groups WHERE groupName=?

it starts return null objects...

its not just this query, it appears to be all queries asking for PRIMARY KEY columns.

Comments (4)

  1. Grace Batumbya

    Repo steps:

            Connection conn = DriverManager.getConnection("jdbc:sqlite:");
            Statement stat = conn.createStatement();
    
            stat.executeUpdate("create table tbl (colid integer primary key AUTOINCREMENT, col varchar)");
            stat.executeUpdate("insert into tbl(col) values (\"foo\")");
    
            PreparedStatement prep = conn.prepareStatement("select colid from tbl where col = ?");
            prep.setString(1, "foo");
            ResultSet rs = prep.executeQuery();
            prep.clearParameters();
            rs.next();
            int result  = rs.getInt(1);
    
  2. Log in to comment