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
bartekkl@gmail.com - 30 Nov 2005 13:35 GMT
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
gagu911@gmx.ch - 30 Nov 2005 15:59 GMT
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
ph@semm.tmfweb.nl - 30 Nov 2005 14:34 GMT
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