db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@debrunners.com>
Subject Re: error when turning off auto commit
Date Fri, 13 May 2005 13:03:08 GMT
Chris wrote:

> Hi,
> to demonstrate the problem, i've written some code which approximates
> the code i'm using.  (attached)
> I'm running Java 1.4.2 with the JVM parameter -Xmx64m.
> If you run the test() method,  the memory used by the JVM  rises to
> above 150mb until the following exception happens:

Thanks for the test case.

I noticed that you are not using PreparedStatements for the query or the
 insert. Using PreparedStatements will make your program much faster, as
the statement does not need to be recompiled every time. This is true
for all JDBC drivers.




PreparedStatement psq = conn.prepareStatement("SELECT id FROM test WHERE
id = ?");
psq.setInt(1, id);
ResultSet rs = psq.executeQuery();

Your code uses a new Statement object to execute every statement, which
can also be avoided since Statement objects are reuseable. Though I
would recommend PreparedStatements.

Also your code never closes the Statement or ResultSet objects it
creates, this may be contributing to the problem.

Applying the above techniques may allow you to progress past this issue,
though it should still be seen as a bug.


View raw message