Subject Re: Bulk insert
Author Roman Rokytskyy
> I am writing a program to insert big text files (up to 300 MB
> 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 :-)

Seems ok to me. One tip: do not use is.executeUpdate() unless you want
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 {
} finally {

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 loop
> correct or should I check if I haven't just commited in the
> insertStr()-method? -

No, calling commit() twice does not make any harm. Driver will take
care of this.

> Do you have any suggestions on how to improve my code? How would you
> choose the number of inserts between commits?

People say something between 1,000 and 10,000. You have to experiment.

Best regards,
Roman Rokytskyy