| To: | "James Carman" <james@xxxxxxxxxxxxxxxxxxxx> |
|---|---|
| Subject: | RE: [cinjug-users] odd db2 insert behavior |
| From: | "Jason Kretzer/STAR BASE Consulting Inc." <JKretzer@xxxxxxxxxxxxxxx> |
| Date: | Mon, 3 May 2004 10:05:59 -0400 |
| Cc: | users@xxxxxxxxxx |
| Delivered-to: | mailing list users@cinjug.org |
| In-reply-to: | <000201c43117$501af7d0$6501a8c0@carmani600m> |
| Mailing-list: | contact users-help@cinjug.org; run by ezmlm |
|
DOH, my mistake, I meant executeUpdate instead of executeQuery. executeUpdate is what I actually have in my code. -Jason
As far as style goes, I would use a PreparedStatement for performance AND safetyâ PreparedStatement ps = connection.prepareStatement( âinsert into some_table(some_pri_key,some_other_value) values (?,âbobâ)â ); for( int i = 0; i < 400; ++i ) { ps.setInt( 1, i ); ps.executeUpdate(); connection.commit(); } You should also be using executeUpdate() rather than executeQuery(), if youâre doing an update. Also, you should probably consider not committing after each insert and putting a bunch of inserts into one commit. -----Original Message----- From: Jason Kretzer/STAR BASE Consulting Inc. [mailto:JKretzer@xxxxxxxxxxxxxxx] Sent: Monday, May 03, 2004 9:42 AM To: users@xxxxxxxxxx Subject: [cinjug-users] odd db2 insert behavior Good morning all, I have a class that populates a db2 database. Here is a basic sample of what I am doing. for(int i=0; i<400; i++) { stmt.executeQuery("INSERT INTO SOME_TABLE (SOME_PRI_KEY, SOME_OTHER_VALUE) VALUES ("+i+",'bob')"); connection.commit(); } First of all, how bad is the style of this? Secondly, when I insert like this and then get the contents of the table, I get something similar to this SOME_PRI_KEY SOME OTHER VALUE 385 bob 386 bob 387 bob 388 bob 389 bob 390 bob 391 bob 392 bob 393 bob 394 bob 395 bob 396 bob 397 bob 398 bob 399 bob 1 bob 2 bob 3 bob 4 bob 5 bob Anyone know why this is happening? Could it just be a timing issue? Thanks, -Jason |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | RE: [cinjug-users] odd db2 insert behavior, James Carman |
|---|---|
| Next by Date: | RE: [cinjug-users] odd db2 insert behavior, Robert Casto |
| Previous by Thread: | RE: [cinjug-users] odd db2 insert behavior, James Carman |
| Next by Thread: | RE: [cinjug-users] odd db2 insert behavior, James Carman |
| Indexes: | [Date] [Thread] [Top] [All Lists] |