求助:为什么用jbuilder连sql2000出问题

hopeshared 04-11-22

搜了很多论坛里的帖子,发现和我问题相似的很多,但是我的问题还是没有解决.
我把jbuilder中的代码做调整,写了一个单独的jsp页面来连接数据库,问题仍然存在.
代码:
代码:
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page contentType="text/html; charset=GB2312" %>

<html>
<head>
<title>DbJsp.jsp</title>
</head>
<body>
<%
try
{
Connection con;
Statement stmt;
ResultSet rs;
Class.forName("net.sourceforge.jtds.jdbc.Driver");
DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver());
String dbUrl = "jdbc:jtds:sqlserver://hopeshared:1433/SMSWeb?useUnicode=true&characterEncoding=GB2312";
String dbUser="s";
String dbPwd="s";
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * from userinfo");
out.println("<table border=1 width=400>");
while (rs.next())
{
String col1 = rs.getString(1);
String col2 = rs.getString(2);
String col3 = rs.getString(3);
out.println("<tr><td>"+col1+"</td><td>"+col2+"</td><td>"+col3+"</td></tr>");
}
out.println("</table>");
rs.close();
stmt.close();
con.close();
}
catch (Exception e) {out.println(e.getMessage());}
%>
</body>

运行结果是connect连不上,也就是在
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
的时候抛出异常,为什么呢?
我的sql默认端口是1433,用s,s能登陆查询分析器并进入SMSWeb这个默认数据库.

hopeshared
2004-11-22 20:00

代码居然没有贴上去
再贴一次


代码:
<%@ page import="java.io.*"%>
<%@ page import=
"java.util.*"%>
<%@ page import=
"java.sql.*"%>
<%@ page contentType=
"text/html; charset=GB2312" %>

<html>
<head>
<title>DbJsp.jsp</title>
</head>
<body>
<%
try
{
Connection con;
Statement stmt;
ResultSet rs;
Class.forName(
"net.sourceforge.jtds.jdbc.Driver");
DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver());
String dbUrl =
"jdbc:jtds:sqlserver://hopeshared:1433/SMSWeb?useUnicode=true&characterEncoding=GB2312";
String dbUser=
"s";
String dbPwd=
"s";
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
stmt = con.createStatement();
rs = stmt.executeQuery(
"SELECT * from userinfo");
out.println(
"<table border=1 width=400>");
while (rs.next())
{
String col1 = rs.getString(1);
String col2 = rs.getString(2);
String col3 = rs.getString(3);
out.println(
"<tr><td>"+col1+"</td><td>"+col2+"</td><td>"+col3+"</td></tr>");
}
out.println(
"</table>");
rs.close();
stmt.close();
con.close();
}
catch (Exception e) {out.println(e.getMessage());}
%>
</body>