Is there a possibility to call a stored procedure on the MSSQL DB without java to wait for a return

G

gagu911

Hello
Im working with jdbc on a MSSQL Database.

In my java client im executing a stored procedure called myProc on the
database.
Im doing this with the following code:

......
Statement stmt = con.createStatement();
String sql1 ="execute myProc";
stmt.execute(sql1);

My problem is, that this stored procedure takes at least one hour to
finish. So i cant close the java client during this time, otherwise the
stored procedure will be canceled. I can call it in a seperate thread,
but that doesnt help. Nevertheless the client cant be closed.

Is there a possibility to call a stored procedure on the MSSQL DB
without java to wait for a return value?

Thanks in advance
G. Agu
 
B

bartekkl

Did you consider maybe running a SQL Server job? You could fire your
procedure from the job, and I guess SQL Server jobs can be run
asynchronously with a SQL statement. If you arrange your application
that way, your Java client can just start the job and quit.

Regards,

Bartosz Klimek
 
P

ph

Couldn't find a solid answer right away, but here goes :
perhaps MSSQL has a connection property 'blocking' that you can set ?
If it doesn't a solution could be to start a different process
altogether, through Runtime's exec.
Let you know if I think of something else..

Paul Hamaker
http://javalessons.com
 
G

gagu911

Thanks Bartosz for the immediate answer!

The hint to use a sql server job helped a lot.
Here is how I solved the problem:
thats the java code:
Statement stmt = con.createStatement();
String sql1 ="USE msdb EXEC sp_start_job 'verdichten'";
System.out.println(sql1);
stmt.execute(sql1);
It is Important to use the msdb Database which is given by MSSQL, there
the sp_start_job procedure is stored.

In MSSQL: The name of my sql job is called 'verdichten'. In this job i
call my stored procedure. The stored procedure is not in msdb, of
course. It's in my own DB i use in the project.

Greetz and 'schönä bim stöhnä'
G. Agu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top