samedi 25 avril 2015

Getting print messages from sqlserver to java application

I have a stored procedure which prints a simple string:

create proc proc1  
as  
print 'Hello World !'

I have an android application which uses servlet (written in Java) for making connection to SQL server Data base. The next code is inside the servlet:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1 = DriverManager.getConnection("Jdbc:Odbc:abc");
CallableStatement cstmt=con1.prepareCall("{call proc1}");
cstmt.execute();

It works fine. The procedure is being activated but now, I want to get the print message 'Hello world !' but the following code doesn't work, and SQLWarning always gets null:

SQLWarning warning = cstmt.getWarnings();
while (warning != null)
{
   System.out.println(warning.getMessage());
   warning = warning.getNextWarning();
}    

My question is how can I get thess print messages? P.S Using raiserror instead of print didn't work as well. I know already about the option of output parameters (I investigated this subject for almost a week). With your permission I would like to ask for another option.

Aucun commentaire:

Enregistrer un commentaire