Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to execute two SQL stmts. simulteneously ?

 
Vikrant
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic