JSP连接SQL Server 2000系统配置
D:\\\\\\\\\\\\\\\\SQLDriverForJDBC\\\\\\\\\\\\\\\\msutil.jar;
追加到CLASSPATH中去,修改后的CLASSPATH如下: 本文来自织梦
CLASSPATH=D:\\\\\\\\\\\\\\\\Java\\\\\\\\\\\\\\\\bin;.;D:\\\\\\\\\\\\\\\\Java\\\\\\\\\\\\\\\\lib;D:\\\\\\\\\\\\\\\\Java\\\\\\\\\\\\\\\\lib\\\\\\\\\\\\\\\\dt.jar;
_D:\\\\\\\\\\\\\\\\Java\\\\\\\\\\\\\\\\lib\\\\\\\\\\\\\\\\tools.jar;D:\\\\\\\\\\\\\\\\LubeeTomcat\\\\\\\\\\\\\\\\common\\\\\\\\\\\\\\\\lib\\\\\\\\\\\\\\\\servlet.jar;
_D:\\\\\\\\\\\\\\\\SQLDriverForJDBC\\\\\\\\\\\\\\\\lib\\\\\\\\\\\\\\\\msbase.jar;D:\\\\\\\\\\\\\\\\SQLDriverForJDBC\\\\\\\\\\\\\\\\lib\\\\\\\\\\\\\\\\mssqlserver.jar;
D:\\\\\\\\\\\\\\\\SQLDriverForJDBC\\\\\\\\\\\\\\\\msutil.jar 本文来自织梦
必须重新启动Tomcat!
这样做的目的是,jsp页面在编译过程中不会出现找不到sql server driver类库的问题
copyright dedecms
写一个简单的用来测试连接SQL Server 2000的JSP代码
<%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" %>
<html>
<body>
<% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs 为你的数据库的
String user="sa";
String password="admin";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select job_id,job_desc from jobs";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) { %>
您的第一个字段内容为:<%=rs.getString(1)%><br>
您的第二个字段内容为:<%=rs.getString(2)%><br>
<% } %>
<% out.print("数据库操作成功,恭喜你"); %> 织梦好,好织梦
<% rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
本文来自织梦
文章评论
共有位Admini5网友发表了评论 查看完整内容