存储过程不在jsp中显示结果 [英] stored procedure is not displaying results in jsp

查看:56
本文介绍了存储过程不在jsp中显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从存储过程中执行结果,但未显示任何内容.我玩过sql语法查询,但是没有任何作用.当我执行普通的select语句时,我从表中获取结果,但是到目前为止,我的存储过程没有任何作用.>

我正在使用sql-server

 <%Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");字符串url ="jdbc:sqlserver://....";字符串username ="something";字符串密码=某物";连接conn = DriverManager.getConnection(URL,用户名,密码);语句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");尝试 {cs.execute();out.println(存储过程成功完成.");} catch(Exception e){out.println(发生以下错误:" + e +< br>"));}%> 

运行了堆栈跟踪

我遇到错误 com.microsoft.sqlserver.jdbc.SQLServerException:'{'附近的语法不正确.

解决方案

要显示该过程的输出,需要执行以下操作

char val =((OracleCallableStatement)cs).getCHAR(3)

记住 OracleCallableStatement 是一个接口它实现了 CallableStatement,OraclePreparedStatement

您可以重写其方法以从可调用语句中获取结果

这些示例也可以为您提供帮助

1.如何使用Java显示表数据存储过程

2.具有输入/输出参数和结果集的存储过程

3.Java已存储程序

希望这会有所帮助!

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 '{'.

解决方案

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 !!

这篇关于存储过程不在jsp中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆