Subject | Possible bug in batch updates |
---|---|
Author | Elias Holman |
Post date | 2004-07-16T20:38:36Z |
Hi all,
I've got an application that batches up a series of updates using
prepared statements. The table has a compound key, and it seems that
when I execute the batch, if two rows share one of the compound key
values, I get a failed primary key constraint error. The code works
perfectly if I take out the batch (call ps.executeUpdate() rather than
ps.addBatch()), and it completes correctly on Oracle. I'm assuming this
is a JDBC issue, not a general database problem since it involves the
JDBC addBatch()/executeBatch() API calls. I've not seen anything similar
on the sourceforge bug list, or in the mailing list archives, so I
apologize if this is a known issue. I built a fresh jar off the CVS,
and it showed this problem, although I discovered it using Jaybird V1.5
Beta 3 from the website, trying it with both Java 1.3 and 1.4. Here is
a code snippet that should duplicate the problem. If this is a bad
snippet, please let me know:
Connection c = DriverManager.
getConnection("jdbc:firebirdsql:localhost:/Projects/testdbs/test1.fdb",
"username", "password");
Statement s = c.createStatement();
s.executeUpdate("CREATE TABLE foo (bar varchar(64) NOT NULL, baz
varchar(8) NOT NULL, CONSTRAINT pk_foo PRIMARY KEY (bar, baz))");
PreparedStatement ps = c.prepareStatement("insert into foo values (?,
?)");
ps.setString(1, "one");
ps.setString(2, "two");
ps.addBatch();
ps.executeBatch();
ps.setString(1, "one");
ps.setString(2, "three");
ps.addBatch();
ps.executeBatch();
That final ps.executeBatch() throws a GDS Exception: 335544665, a
primary key violation. Removing the first executeBatch fixes the
problem, as does simply calling executeUpdate() instead of addBatch()
executeBatch() each time, which is why I believe it is a problem with
batching. Please let me know if I can provide more info.
--
Eli
I've got an application that batches up a series of updates using
prepared statements. The table has a compound key, and it seems that
when I execute the batch, if two rows share one of the compound key
values, I get a failed primary key constraint error. The code works
perfectly if I take out the batch (call ps.executeUpdate() rather than
ps.addBatch()), and it completes correctly on Oracle. I'm assuming this
is a JDBC issue, not a general database problem since it involves the
JDBC addBatch()/executeBatch() API calls. I've not seen anything similar
on the sourceforge bug list, or in the mailing list archives, so I
apologize if this is a known issue. I built a fresh jar off the CVS,
and it showed this problem, although I discovered it using Jaybird V1.5
Beta 3 from the website, trying it with both Java 1.3 and 1.4. Here is
a code snippet that should duplicate the problem. If this is a bad
snippet, please let me know:
Connection c = DriverManager.
getConnection("jdbc:firebirdsql:localhost:/Projects/testdbs/test1.fdb",
"username", "password");
Statement s = c.createStatement();
s.executeUpdate("CREATE TABLE foo (bar varchar(64) NOT NULL, baz
varchar(8) NOT NULL, CONSTRAINT pk_foo PRIMARY KEY (bar, baz))");
PreparedStatement ps = c.prepareStatement("insert into foo values (?,
?)");
ps.setString(1, "one");
ps.setString(2, "two");
ps.addBatch();
ps.executeBatch();
ps.setString(1, "one");
ps.setString(2, "three");
ps.addBatch();
ps.executeBatch();
That final ps.executeBatch() throws a GDS Exception: 335544665, a
primary key violation. Removing the first executeBatch fixes the
problem, as does simply calling executeUpdate() instead of addBatch()
executeBatch() each time, which is why I believe it is a problem with
batching. Please let me know if I can provide more info.
--
Eli