Subject | Re: Bulk insert |
---|---|
Author | Roman Rokytskyy |
Post date | 2003-07-09T22:13:53Z |
> I am writing a program to insert big text files (up to 300 MBSeems ok to me. One tip: do not use is.executeUpdate() unless you want
> containing approximatelty 750000 rows of data, the longest record is
> 1000 chars) into a firebird 1.5 rc3 database. I am a java-newbie and
> wanted to ask the experts in this forum if my code looks good :-)
to know the number of inserted/updated/deleted records. This
information is not available after statement execution and driver has
to do additional call to the server. Simple is.execute() will be enough.
Also, in order to prevent resource leaks, use following template for
connections and statements:
Connection con = getMyConnection();
try {
...
PreparedStatement stmt = con.prepareStatement(sql);
try {
...
} finally {
stmt.close();
}
} finally {
con.close();
}
Try to keep connection allocation and de-allocation within one method.
If you have to call this method many times, use connection pooling.
Try to keep statement allocation and de-allocation within one
try/finally block for connection. If you have to allocate statement
many times, look for a connection pool that supports statement pooling.
> One more question: Is the call to commit() after the while loopNo, calling commit() twice does not make any harm. Driver will take
> correct or should I check if I haven't just commited in the
> insertStr()-method? -
care of this.
> Do you have any suggestions on how to improve my code? How would youPeople say something between 1,000 and 10,000. You have to experiment.
> choose the number of inserts between commits?
Best regards,
Roman Rokytskyy