主题:tomcat4.1+sqlserver2000,我的数据库连不上去,求问大家了。急~~~
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<HTML>
<BODY>
<% 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:1490;DatabaseName=testDatabse","sa","123456");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM userTable");
out.print("<Table Border>");
out.print("<TR><td colspan=8 align=center>用户数据</td></tr>");
out.print("<TR>");
out.print("<Td width=100 >"+"用户ID号");
out.print("<Td width=50 >"+"用户名");
out.print("<Td width=100>"+"用户真实姓名");
out.print("<Td width=50>"+"年龄");
out.print("<Td width=50>"+"性别");
out.print("<Td width=100>"+"联系地址");
out.print("<Td width=100>"+"联系电话");
out.print("<Td width=100>"+"添加时间");
out.print("</TR>");
while(rs.next())
{ out.print("<TR>");
out.print("<TD >"+rs.getLong(1)+"</TD>");
out.print("<TD >"+rs.getString(2)+"</TD>");
out.print("<TD >"+rs.getString(4)+"</TD>");
out.print("<TD >"+rs.getInt("user_age")+"</TD>");
out.print("<TD >"+rs.getString("user_sex")+"</TD>");
out.print("<TD >"+rs.getString("user_address")+"</TD>");
out.print("<TD >"+rs.getString("user_telephone")+"</TD>");
out.print("<TD >"+rs.getString("add_time")+"</TD>");
out.print("</TR>") ;
}
out.print("</Table>");
con.close();
}
catch(SQLException e1)
{
out.print("SQL异常!");
}
%>
</BODY>
</HTML>
运行结果就是:SQL异常。但是我已经照样子,把JDBC要用到的三个包(msutil.jar,mssqlserver.jar,msbase.jar)放到tomcat/common/lib
下了。是不是数据库连接有问题啊。我的SQLServer2000放在了c:/programme files下。tomcat放在e盘下。实在搞不懂了。表也建立了,还插
了几条数据进去,数据库名:testDatabse,表名:userTable,SQLSERVER的用户名是sa,密码是123456.谢谢大家了。
<%@ page import="java.sql.*" %>
<HTML>
<BODY>
<% 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:1490;DatabaseName=testDatabse","sa","123456");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM userTable");
out.print("<Table Border>");
out.print("<TR><td colspan=8 align=center>用户数据</td></tr>");
out.print("<TR>");
out.print("<Td width=100 >"+"用户ID号");
out.print("<Td width=50 >"+"用户名");
out.print("<Td width=100>"+"用户真实姓名");
out.print("<Td width=50>"+"年龄");
out.print("<Td width=50>"+"性别");
out.print("<Td width=100>"+"联系地址");
out.print("<Td width=100>"+"联系电话");
out.print("<Td width=100>"+"添加时间");
out.print("</TR>");
while(rs.next())
{ out.print("<TR>");
out.print("<TD >"+rs.getLong(1)+"</TD>");
out.print("<TD >"+rs.getString(2)+"</TD>");
out.print("<TD >"+rs.getString(4)+"</TD>");
out.print("<TD >"+rs.getInt("user_age")+"</TD>");
out.print("<TD >"+rs.getString("user_sex")+"</TD>");
out.print("<TD >"+rs.getString("user_address")+"</TD>");
out.print("<TD >"+rs.getString("user_telephone")+"</TD>");
out.print("<TD >"+rs.getString("add_time")+"</TD>");
out.print("</TR>") ;
}
out.print("</Table>");
con.close();
}
catch(SQLException e1)
{
out.print("SQL异常!");
}
%>
</BODY>
</HTML>
运行结果就是:SQL异常。但是我已经照样子,把JDBC要用到的三个包(msutil.jar,mssqlserver.jar,msbase.jar)放到tomcat/common/lib
下了。是不是数据库连接有问题啊。我的SQLServer2000放在了c:/programme files下。tomcat放在e盘下。实在搞不懂了。表也建立了,还插
了几条数据进去,数据库名:testDatabse,表名:userTable,SQLSERVER的用户名是sa,密码是123456.谢谢大家了。