db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris <ch...@visual-i.co.uk>
Subject Re: error when turning off auto commit
Date Fri, 13 May 2005 14:43:11 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<body bgcolor="#ffffff" text="#000000">
Hi Dan,<br>
thanks very much for the advice.&nbsp;&nbsp; Recyling the same statement
significantly reduces the memory problem, and using prepared statements
is *really* speeding up my code.<br>
Daniel John Debrunner wrote:
<blockquote cite="mid4284A58C.30109@debrunners.com" type="cite">
  <pre wrap="">Chris wrote:

  <blockquote type="cite">
    <pre wrap="">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:
  <pre wrap=""><!---->
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.


<a class="moz-txt-link-freetext" href="http://incubator.apache.org/derby/manuals/tuning/perf21.html#HDRSII-PERF-18705">http://incubator.apache.org/derby/manuals/tuning/perf21.html#HDRSII-PERF-18705</a>


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