Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How I can call Stored Procedure asynchronously from java function

 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JDBC.
 
john guthrie
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can u give me some idea how i can use throwaway thread in my function.
Thanks & Regards
Bikash
 
john guthrie
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
}
}
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic