环境设置:jdbc驱动程序
1.msbase.jar,mssqlserver.jar,msutil.jar复制到tomcat目录\common\lib\
2.设置环境变量classpath
数据库环境
sql-server2000(sp4补丁)
服务器环境
tomcat5.0虚拟服务器设置
1.编辑tomcat目录\conf\server.xml,添加
<Context path="/friends" reloadable="true"
docBase="E:\eclipse\workspace\friends"
workDir="E:\eclipse\workspace\friends\work">
</Context> |
path:虚拟服务器名
docBase:物理路径
workDir:工作目录
reloadable="true"默认
2.启动tomcat服务
编写jsp文件
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>Insert title here</title>
<body>
<%
//变量声明
Connection conn;
ResultSet rs;
Statement st;
//变量声明结束
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//jdbc驱动
//数据库连接字符串
String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=zy";
conn= DriverManager.getConnection(url,"sa",""); //设置conn
//设置st
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery("select * from zyInfo");//sql查询语句
while(rs.next()){
out.println(rs.getString("zyInfoID"));//循环读取字段
}
%>
</body>
</html> | |