jdbc 连接sql2000数据库 设置方式
扫描二维码
随时随地手机看文章
重新启动Tomcat!
写个sql 测试的sql_test.jsp 文件 内容如下<%@ page contentType="text/html;charset=GB2312" %><%@ page import="java.sql.*" %>
<% Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e)
{
out.print("类找不到!");
}
try
{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabse","sa","sa");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM userTable");
out.print("
用户数据 | |||||||
"+"用户ID号"); out.print(" | "+"用户名"); out.print(" | "+"用户真实姓名"); out.print(" | "+"年龄"); out.print(" | "+"性别"); out.print(" | "+"联系地址"); out.print(" | "+"联系电话"); out.print(" | "+"添加时间"); out.print(" |
"+rs.getLong(1)+" | ");"+rs.getString(2)+" | ");"+rs.getString(4)+" | ");"+rs.getInt("user_age")+" | ");"+rs.getString("user_sex")+" | ");"+rs.getString("user_address")+" | ");"+rs.getString("user_telephone")+" | ");"+rs.getString("add_time")+" | ");
con.close();
}
catch(SQLException e1)
{
out.print("SQL异常!");
}
%>
保存完放在 C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/ROOT这里 然后 打开ie 输入http://localhost:8080/sql_test.jsp