stored procedure is not displaying results in jsp

孤人 提交于 2021-02-11 12:54:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!