日期:2014-05-19  浏览次数:20532 次

JSP调用存储过程,传递参数问题。谢谢。
HTML code

<%
            String teamName = new String(request.getParameter("fullName").getBytes(
            "ISO8859-1"), "UTF-8");
            String userId = request.getParameter("userId");
            Class.forName("net.sourceforge.jtds.jdbc.Driver")
                    .newInstance();
            String url = "jdbc:jtds:sqlserver://X.X.X.X:1433/sportSys";
            String user = "sa";
            String password = "123";
            Connection conn = DriverManager.getConnection(url, user, password);
            //CallableStatement proc = conn.prepareCall("{CALL jianXiang('"+userId+"',' "+teamName+"')}");
            CallableStatement proc = conn.prepareCall("{CALL jianXiang('9','男子')}");
            
            ResultSet rs = proc.executeQuery();
            ResultSetMetaData dm = rs.getMetaData();
        %>



上面的代码换成注释的部分,就不行了,页面没有结果。

页面输出userId和teamName的时候,是有值的呢。
HTML code

<%=userId %>(这个的值为9) <%=teamName %>(这个的值为"男子")



请问这是为啥呢?


------解决方案--------------------
这种问题,首先要怀疑是不是“空格”在作祟。。。

比如我看你这段:
//CallableStatement proc = conn.prepareCall("{CALL jianXiang('"+userId+"',' "+teamName+"')}");
里面:
单引号和双引号之间就有个空格。

最终字符串变成:
"{CALL jianXiang('9',' 男子')}"