Bug in sqlite-jdbc-3.6.4.1: Statement.executeBatch() does not clear command batch

592 views
Skip to first unread message

MAILER-DAEMON

unread,
Nov 11, 2008, 8:18:26 AM11/11/08
to Xerial
Hi,

I found the following code does not work as expected:

stat.executeUpdate("drop table if exists t;");
stat.executeUpdate("create table t (c text);");
prep = conn.prepareStatement("insert into t values (?);");
prep.setString(1, "a");
prep.addBatch();
System.out.println("call 1: " + prep.executeBatch().length);
prep.setString(1, "b");
prep.addBatch();
System.out.println("call 2: " + prep.executeBatch().length);

rs = stat.executeQuery("select * from t;");

while (rs.next())
System.out.println(rs.getString(1));

Output:
call 1: 1
call 2: 2
a
a
b

The expected result (and what I get with MySQL driver) would be:
call 1: 1
call 2: 1
a
b

That is, the call to executeBatch() should delete the commands in the
batch and not execute them again on the next call.

Regards,
Thomas.

Taro L. Saito

unread,
Nov 16, 2008, 7:04:54 PM11/16/08
to Xerial
Hi,

I am not sure which behavior is truely expected in the JDBC
specification:
http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec2/jdbc2.1.frame6.html#287821

However, it seems that each call of executeBatch() method do the
updates
to the database, so the first result makes sense to me in that
it correctly returns the number of SQL queries executed.

Taro L. Saito

unread,
Nov 16, 2008, 7:43:11 PM11/16/08
to Xerial
Hi Thomas,

It seems that you are correct. I found the following part in the JDBC
document:
http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec2/jdbc2.1.frame6.html#287821

- The statement's internal list of batch elements is reset to empty
once executeBatch() returns.

The executeBatch() method has to clear the internal list after the
execution.

However, I cannot find any description in JDBC API about the state of
the batch after the execution.. umm
http://java.sun.com/j2se/1.3/docs/api/java/sql/Statement.html#executeBatch()

Anyway, I'd like to fix the bug, but I have no time to do this for a
couple of weeks..

Thanks for your report.

> Hi,
>
> I am not sure which behavior is truely expected in the JDBC
> specification:http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec2/jdbc2.1.frame6.htm...

julianbui

unread,
Dec 8, 2008, 2:53:52 PM12/8/08
to Xerial
Also found the same thing. I had to close the PS and create a new
one. This is slightly different than the other jdbc usages I've seen.
Reply all
Reply to author
Forward
0 new messages