Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / May 2007

Tip: Looking for answers? Try searching our database.

Slow performance with SQL and stmt.executeUpdate()

Thread view: 
John Gordon - 25 May 2007 22:35 GMT
I have an application that writes to an Oracle SQL database.  The main
loop reads one data record from an external source, splits it into
fields then writes it to a database table with a Statement.ExecuteUpdate
method call, using SQL insert.

The whole program is too big to post here, but this is the gist of it:

 Connection conn = DriverManager.getConnection(...);
 Statement stmt = conn.createStatement();

 while(externalSourceHasData)
 {
   MyData md = readRecordFromExternalSource();

   String name = md.getName();
   String phone = md.getPhone();
   String address = md.getAddress();

   stmt.executeUpdate("insert into mytable values ('" + name +
     "','" + phone + "','" + address + "')");
 }

 conn.close();

Performace is somewhat of an issue.  It's marginally acceptable, but would
be nice if it were faster.  Is there anything obvious that I'm doing wrong
here?

One thing I considered was turning off auto-commit, then doing a commit
after the loop is finished.  Would this make a noticable difference on
200k records?

Also, is there a way to write more than one record at a time?  Some sort
of batch-writing capability?

Thanks for any suggestions.

Signature

John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                               -- Edward Gorey, "The Gashlycrumb Tinies"

joeNOSPAM@BEA.com - 25 May 2007 23:02 GMT
> I have an application that writes to an Oracle SQL database.  The main
> loop reads one data record from an external source, splits it into
[quoted text clipped - 37 lines]
> gor...@panix.com              B is for Basil, assaulted by bears
>                                 -- Edward Gorey, "The Gashlycrumb Tinies"

Hi, yes. Look at the Statement addBatch() and executeBatch() calls.

Joe Weinstein at BEA Systems
Alfred - 27 May 2007 06:55 GMT
> ...
> Hi, yes. Look at the Statement addBatch() and executeBatch() calls.
>
> Joe Weinstein at BEA Systems

To OP: And use PreparedStatement for operations like this
because on server side it will be a precompiled procedure
after creating.

Alfred


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.