This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes How to execute two SQL stmts. simulteneously ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to execute two SQL stmts. simulteneously ?" Watch "How to execute two SQL stmts. simulteneously ?" New topic
Author

How to execute two SQL stmts. simulteneously ?

Vikrant
Greenhorn

Joined: Jun 20, 2000
Posts: 4
When using prepareStatement(String sqlstatement), I want to know how to execute more than one sql statements simulteneously ? Like creating a table and inserting a record while using one prepareStatement(String sqlstatement).
stat=con.prepareStatement("insert into searchResult b_number,b_name,b_author,b_publisher,topic,date_of_postage) values(?,?,?,?,?,?)");
The above is with only one sql statement, what if I want to create a table before inserting in the same prepareStatement().
Certainly, there is a way out, but I do not know.

Harish Kashyap
Ranch Hand

Joined: Jun 14, 2000
Posts: 118
There is no way to execute more than one sql query simultaneously . It depends on the database u r using whether it allows u to do it or not. generally database servers perform multitasking, there it is possible using multithreading in java. one connection accesses the database through a dsn which is explicitly locked so it is possible only through multithreading that too u should not use jdbc-odbc bridge driver. it does not provide this facility.
Milind Kulkarni
Ranch Hand

Joined: Jun 01, 2000
Posts: 146
Hi Vikrant,
You can execute multiple SQL statements by bunching them together as a Stored Procedure and then call CallableStatement object to execute the stored procedure.
Regards,
Milind
Sam
Greenhorn

Joined: Jun 23, 2000
Posts: 26
Hi Milind,
Things will get more clearer if you can kindly give an example.
Waiting for the reply.
Regards,

Originally posted by Milind Kulkarni:
Hi Vikrant,
You can execute multiple SQL statements by bunching them together as a Stored Procedure and then call CallableStatement object to execute the stored procedure.
Regards,
Milind

Milind Kulkarni
Ranch Hand

Joined: Jun 01, 2000
Posts: 146
Hi Sam,
Stored procedure that is stored in a database can be called using CallableStatement object.
Here are 2 simple examples of CallableStatement object:
Example 1:
CallableStatement cstmt = con.prepareCall("{call getValues(?, ?)}");
Here Connection method prepareCall is used to create a CallableStatement Object. The example above creates an instance of CallableStatement that contains a call to the stored procedure getValues. It has two arguments and no result parameter.
Example 2:
CallableStatement cstmt = con.prepareCall("{? = call getValues[(?, ?, ...)]}");
Here procedure returns a result parameter.
Hope this helps !!
Regards,
Milind

[This message has been edited by Milind Kulkarni (edited July 01, 2000).]
Amit Zzz Kulkarni
Ranch Hand

Joined: Jul 05, 2000
Posts: 30
Milind ,
I think you can also call it through a cursor though I am not sure.

Originally posted by Milind Kulkarni:
Hi Vikrant,
You can execute multiple SQL statements by bunching them together as a Stored Procedure and then call CallableStatement object to execute the stored procedure.
Regards,
Milind
 
Have you checked out Aspose?
 
subject: How to execute two SQL stmts. simulteneously ?
 
jQuery in Action, 3rd edition