File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes Batch Execution in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Batch Execution in JDBC" Watch "Batch Execution in JDBC" New topic

Batch Execution in JDBC

Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello Everybody,
How to use different PreparedStatements in a single batch?
if i have a 1st prepared statemnt like
insert into emp values(?,?,?,?)
& second one:
delete from emp where empid=?

then how these statements could be added in a single batch & executed?

i hope the question is clear.

Shrinivas Mujumdar
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
You can't do that (have different prepared statements in one batch).

When you batch prepared statements it is the same statement each time only the parameters for the statement are batched.
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
That means it is the limitation of Batch Execution in JDBC & such issues can only be handled using Stored Procedures. Any other solution than that.?


Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
A stored procedure is usually a good choice if there are lesser calls to the procedure and much processing which could be handled on the DB end.
I am not sure if your case would exactly suit that. But I guess it would give you some (minor IMO) improvement in the performance.

Cheers!<br /><b>Annie</b>
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Thanks a Lot!!!
I agree. Here's the link:
subject: Batch Execution in JDBC
Similar Threads
DOM issue
SQL Exception:General Error
How to execute multiple batch file ?
multiple prepared statemnets using executeBatch