GeeCON Prague 2014*
The moose likes JDBC and the fly likes How I can call Stored Procedure asynchronously from java function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "How I can call Stored Procedure asynchronously from java function" Watch "How I can call Stored Procedure asynchronously from java function" New topic
Author

How I can call Stored Procedure asynchronously from java function

Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi,
I want to call one Stored Procedure from java function asynchronously that means my function should not wait whether that Stored Procedure executed or not.It should simply call that Stored Procedure and it should not wait for execution.Can any one please guide me how i can do that.
Below r my codes :-

Thanks & Regards
Bikash
[ February 09, 2004: Message edited by: Bikash Paul ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Moving to JDBC.


[Jess in Action][AskingGoodQuestions]
john guthrie
Ranch Hand

Joined: Aug 05, 2002
Posts: 124
i think jdbc calls are all blocking. given that, you can start up a "throwaway" thread to do the call, then have your main thread start up the throwaway and carry on. the extra thread just exits when the stored procedure call returns
Bikash Paul
Ranch Hand

Joined: Dec 04, 2001
Posts: 342
Hi,
Can u give me some idea how i can use throwaway thread in my function.
Thanks & Regards
Bikash
john guthrie
Ranch Hand

Joined: Aug 05, 2002
Posts: 124
sorry, i meant that you just create a thread to do the SP call, then exit. just a regular java thread, pooled or otherwise.
Mani Narayanan
Greenhorn

Joined: Feb 20, 2004
Posts: 5
Jus try out this code
//this call is the thread class where one will execute the store procedure
class DBProcess implements Runnable
{
private String sp_name;
DBProcess(String sp_name)
{
this.sp_name = sp_name
}

public void run() throws Exception
{
Connection conn = null;
CallableStatement cstmt= null;
try
{
conn = connect("Pdr");
String query = "{ call "+ sp_name+"(?) }";
cstmt = conn.prepareCall(query);
cstmt.setString(1,"PDR_USER");
cstmt.execute();
}
finally
{
if(cstmt != null)
cstmt.close();
if(conn != null)
close(conn);
}
}
}
the following is the calling class
class RunDB
{

public static void main (String[] args)
{
if (args.length > 0)
{
DBProcess db = new DBProcess (args[0]);
try
{
new Thread(db).start();
}
catch (IllegalThreadStateException e)
{
//add code
}
catch (Exception e)
{
//add code
}
}
}
}
 
GeeCON Prague 2014
 
subject: How I can call Stored Procedure asynchronously from java function