主题: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>
<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>