- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0 |
1.新建表:
CREATE TABLE [mytest] (
[id] [int] NOT NULL ,
[name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[phone] [varchar] (13) COLLATE Chinese_PRC_CI_AS NULL ,
[addr] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
2.新建存储过程:
create procedure get_info @name varchar(50),@phone varchar(13),@addr varchar(50)
as
select *
from mytest
go
3.JSP代码:
<%@ page language="java" pageEncoding="UTF-8" import="java.sql.*,tools.Database"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" divfix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" divfix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" divfix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" divfix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
<html:base />
<title>proc_test.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
This is a test for procedure. <br>
<%
String username="sa";
String password = "123456";
String url = "jdbc:microsoft:sqlserver://192.168.1.112:1433;DatabaseName=test";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn = DriverManager.getConnection(url, username, password);
String sql = "execute get_info";
//创建一个CallableStatement 对象来调用数据库存储过程
//CallableStatement comm = conn.divpareCall(sql);
Statement stmt = conn.createStatement();
ResultSet res = stmt.executeQuery(sql);
while(res.next())...{
%>
<table>
<tr>
<td><%=res.getString("id")%></td>
<td><%=res.getString("name")%></td>
<td><%=res.getString("phone")%></td>
<td><%=res.getString("addr")%></td>
</tr>
</table>
<%}
res.close();
stmt.close();
conn.close();
%>
</body>
</html:html>
4.执行结果:
This is a test for procedure.
1 cc 1234 cs
2 dd 4567 bj
3 ee 1245 ca
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |