回 帖 发 新 帖 刷新版面

主题:JSP中执行存储过程!

<%@ page contentType="text/html; charset=GBK"  import="java.sql.*" %>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<h1>
<%
   try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection
          con = DriverManager.getConnection("Jdbc:Odbc:LocalServer", "sa", "");
      //存储过程名
          String procedure_name="proc_view";
          String call_procedure_string="{call " + procedure_name + "(?,?,?,?)}";
          System.out.println("调用字符串为:" + call_procedure_string);
      //创建对象
          CallableStatement callable_statement=con.prepareCall(call_procedure_string);
      //注册输出参数(第7个问号)
          callable_statement.registerOutParameter(4,java.sql.Types.INTEGER);
          callable_statement.setString(1,"usename");
          callable_statement.setString(2,"111");
          callable_statement.setString(3, "5,2,4,3");

          callable_statement.execute();
          System.out.println(callable_statement.getInt(4));
              }
    catch (Exception e)
    {
      e.printStackTrace();
    }
%>
</h1>
</body>
</html>

回复列表 (共1个回复)

沙发

我的程序是这样的,不知道那里错了,运行错误:
org.apache.jasper.JasperException
java.lang.NullPointerException
帮忙看看吧
<%@ page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>

<html>
     <head>
          <title> System_database_bak.jsp </title>
     </head>
     <body>
     <%
       Connection conn = null;
       //Statement stmt = null;
       String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=YLHRMS";
         String user = "yyj";
         String password = "yyj";
       try
         {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            conn = DriverManager.getConnection(url,user,password);
            //stmt = conn.createStatement();
          
          //存储过程名
          String procedure_name="pr_AutoBackup";
          String call_procedure_string="{call " + procedure_name + "(?,?,?,?)}";
          //创建对象
          CallableStatement cstmt=conn.prepareCall(call_procedure_string);
          //设置输入参数
          cstmt.setString(1,"YLRHMS");
          cstmt.setString(2,"");
          cstmt.setInt(3,24);
          cstmt.setInt(4,1);
          //cstmt.registerOutParameter();
          cstmt.execute();
        }
        
          catch (Exception e)
        {
           e.printStackTrace();
        }

          finally
          {
            
            //cstmt.close();
            conn.close();
          }
     %>
     </body>
</html>

我来回复

您尚未登录,请登录后再回复。点此登录或注册