JSP调用MySQL存储过程(带参数) - 代码发芽网

来源:百度文库 编辑:神马文学网 时间:2024/04/29 13:54:10
Java Server Page语言: JSP调用MySQL存储过程(带参数)<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="beans.DBUtil" %>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



 
   
   
    My JSP 'Proc.jsp' starting page
   
   
   
       
   
   
   

 
 
 
    <%
        DBUtil db = new DBUtil();
        Connection conn = db.getConnection();
        CallableStatement cs = conn.prepareCall("{call P_setAgeBySno(?,?,?)}");
        //set the input parameter
        cs.setString("no","2");
        cs.setInt(2,199);
        //sert the output parameter
        cs.registerOutParameter("name",Types.CHAR);
        cs.execute();
           String result = cs.getString(3);
        out.print("Data from executing the procedure:
");
        out.print(result);
        if(cs != null)
            cs.close();
        if(conn != null)
            conn.close();
     %>