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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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