JSP调用带参数的SQL存储过程

john_wujy 2011-07-29 04:58:01
怎么样实现用JSP语句JSP调用带参数的SQL存储过程,我的存储过程用三个参数,分别是 name , sex ,age 。我已经将录入的值传输给了参数。
String name= request.getParameter("name");
String sex= request.getParameter("sex");
String age= request.getParameter("age");

请各位高手给出答案。谢谢!
...全文
115 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
john_wujy 2011-08-03
  • 打赏
  • 举报
回复
非常感谢热心人的帮助,问题已经解决了!
john_wujy 2011-08-02
  • 打赏
  • 举报
回复
不报错,没反应。存储过程不执行
kafen88 2011-08-02
  • 打赏
  • 举报
回复
报错还是没反应。。。
john_wujy 2011-08-02
  • 打赏
  • 举报
回复
代码如下:
<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="org.hibernate.Transaction.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>报表一</title>
</head>

<p style=line-height: 150%>
<%@ page import="java.sql.*"%> <%--不要忘了引入sql 包--%>
<p style=line-height: 150%>
<body bgcolor="#ffffff">
<%
String name = request.getParameter("name")
String sex = request.getParameter("sex");
String age = request.getParameter("age");
%>

<p style=line-height: 150%>

<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:gpsway"; //数据库名为gpsway
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();

CallableStatement st = conn.prepareCall("{call wu_gd(?, ?, ?)}"); //存储过程是wu_gd
st.setString(1, name);
st.setString(2, sex);
st.setString(3, age);
st.executeUpdate();
stmt.close();
conn.close();

%>

<p style=line-height: 150%></body>
</html>
john_wujy 2011-08-02
  • 打赏
  • 举报
回复
按照楼上的做法,存储过程没有执行。不知道是怎么回事?
magong 2011-07-29
  • 打赏
  • 举报
回复
<%@ page import="java.sql.*" %>

<%
CallableStatement st = dbconn.prepareCall("{call 存储过程名(?, ?, ?)}");
st.setString(1, name);
st.setString(2, sex);
st.setString(3, age);
st.execute(); //根据情况使用:execteUpdate(), executeQuery()
...
%>

23,409

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧