I have written code which should call MSSQL 2005 procedure from my servlet. The problem is the procedure is to SELECT data from table so I want to get ResultSet but the result set is never returns :( I tested the procedure with another procedure and it works, moreover, the client connection privileges are dbowner so there should be no problem with connection but still the execute returns false :(
Here is the problem code (current connection is connected I checked):
...
SQLServerCallableStatement callableStatement = null;
callableStatement = (SQLServerCallableStatement) connection.prepareCall(
"{call "+
DATABASE_NAME+
"."+
SCHEMA_NAME+
".select_item_proc(?,?,?)}");
callableStatement.setInt(1, 0);
callableStatement.setString(2, "value1");
callableStatement.setString(3, "value2")开发者_开发技巧;
boolean rs=callableStatement.execute();
if(rs)
{
ResultSet result=callableStatement.getResultSet();
while (result.next()) {
String col1= result.getString(1);
String col2=result.getString(2);
System.out.print(col1+",");
System.out.println(col2);
}
}
...
So I need your fresh sight what the problem really can be? Any useful comment is appreciated
Please try using ResultSet rs = callableStatement.executeQuery();
instead of the boolean rs=callableStatement.execute();
line.
精彩评论