问题
I am trying to execute results from my stored procedure and it is not displaying anything. I have played around with sql syntax query and nothing worked...when I do a normal select statement I get results from my tables, but so far nothing worked with my stored procedure...what am I not getting results ?
I am using sql-server by the way
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://....";
String username = "something";
String password = "something";
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
ResultSet rs;
CallableStatement cs;
cs = conn.prepareCall("{ exec rptGetAssetbyLocation(?, ?,?,?,?,?) }");
cs.setString(1, "name");
cs.setString(2, "model");
cs.setString(3, "serialNumber");
cs.setString(4, "type");
cs.setString(5, "condition");
cs.setString(6, "note");
try {
cs.execute();
out.println("Stored procedure completed successfully.<br>");
} catch (Exception e) {
out.println("The following error occurred: " + e + "<br>");
}
%>
edit:
ran a stacktrace
I am getting an error com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '{'.
回答1:
To display the output from the procedure to need to do something like this
char val= ((OracleCallableStatement)cs).getCHAR(3)
Remember OracleCallableStatement is an interface which implements CallableStatement, OraclePreparedStatement
You can override its method to get the results from the callable statments
Also these examples would help you
1.how to display tabledata with java stored procedure
2.Stored procedure with Input/Output parms and a ResultSet
3.Java Stored procedures
Hope this helps !!
来源:https://stackoverflow.com/questions/22978212/stored-procedure-is-not-displaying-results-in-jsp