Try to delete a record. The record is deleted but executeUpdate() always returns 0!

121 views
Skip to first unread message

Jim

unread,
May 31, 2012, 4:58:54 AM5/31/12
to H2 Database
I am using H2 embeded database.
I try to delete a record from a table as follows:

PreparedStatement stmt = connection.prepareStatement("DELETE FROM
MYTABLE WHERE id= ?", Statement.NO_GENERATED_KEYS);
stmt.setObject(1, "1234");
int result = stmt.executeUpdate();

The row is deleted but return count is always 0!
Is this a bug? Am I doing something wrong here?

Thomas Mueller

unread,
Jun 4, 2012, 4:43:31 AM6/4/12
to h2-da...@googlegroups.com
Hi,

Maybe the row was deleted before executing the statement? Could you provide a complete, simple, reproducible test case please?

Regards,
Thomas
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Jim

unread,
Jun 11, 2012, 4:20:23 AM6/11/12
to H2 Database
Hi,
The row is indeed deleted but for some reason the executeUpdate
returns 0 as the num. of updated rows.
I can send you a test case, but just to be sure what do you mean when
you say that the "row was deleted before executing the statement"?
My scenario is the following sequence of actions:
1) Delete row X from table A. Success and executeUpdate returns 1.
2) Delete row Y from table B. Row is deleted but executeUpdate returns
0.


On Jun 4, 11:43 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>
> Maybe the row was deleted before executing the statement? Could you provide
> a complete, simple, reproducible test case please?
>
> Regards,
> Thomas
>
>
>
>
>
>
>
> On Thursday, May 31, 2012, Jim wrote:
> > I am using H2 embeded database.
> > I try to delete a record from a table as follows:
>
> > PreparedStatement stmt = connection.prepareStatement("DELETE FROM
> > MYTABLE WHERE id= ?", Statement.NO_GENERATED_KEYS);
> > stmt.setObject(1, "1234");
> > int result = stmt.executeUpdate();
>
> > The row is deleted but return count is always 0!
> > Is this a bug? Am I doing something wrong here?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "H2 Database" group.
> > To post to this group, send email to h2-da...@googlegroups.com<javascript:;>
> > .
> > To unsubscribe from this group, send email to
> > h2-database...@googlegroups.com <javascript:;>.

Thomas Mueller

unread,
Jun 13, 2012, 1:45:53 PM6/13/12
to h2-da...@googlegroups.com
Hi,

> I can send you a test case, but just to be sure what do you mean when
> you say that the "row was deleted before executing the statement"?

What I mean is that the row you tried to delete in 2) didn't actually
exist at the time the delete statement was run. Maybe it was deleted
before, or never inserted. To verify, I suggest to run a SELECT
statement first, and print the row to System.out. And make sure you
only use one thread, to avoid race conditions.

> My scenario is the following sequence of actions:
> 1) Delete row X from table A. Success and executeUpdate returns 1.
> 2) Delete row Y from table B. Row is deleted but executeUpdate returns
> 0.

Regards,
Thomas
Reply all
Reply to author
Forward
0 new messages