jdbc联接MS sqlserver2000时出错,如何解决?(50分)

  • 主题发起人 主题发起人 tony.xu
  • 开始时间 开始时间
T

tony.xu

Unregistered / Unconfirmed
GUEST, unregistred user!
jdbc联接MS sqlserver2000时出错,如何解决?
jdbc sql server 2000的三个jar包已经加入classpath, 这到底是什么问题呀刚才一会儿还好的 ,怎么说不行就不行了呢?
出错信息:
500 Servlet Exception
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error
establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at _page__jsp._jspService(/page.jsp:61)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:497)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:342)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:272)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:484)

--------------------------------------------------------------------------------
Resin 2.1.6 (built Fri Nov 8 08:18:18 PST 2002)

代码如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%
//变量声明
java.sql.Connection sqlCon;
//数据库连接对象
java.sql.Statement sqlStmt;
//SQL语句对象
java.sql.ResultSet sqlRst;
//结果集对象
java.lang.String strCon;
//数据库连接字符串
java.lang.String strSQL;
//SQL语句
int intPageSize;
//一页显示的记录数
int intRowCount;
//记录总数
int intPageCount;
//总页数
int intPage;
//待显示页码
java.lang.String strPage;

int i,j,k;
//设置一页显示的记录数
intPageSize = 5;
//取得待显示页码
strPage = request.getParameter("page");

if(strPage==null){
//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;

} else
{
//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);

if(intPage<1) intPage = 1;
}
//装载JDBC-ODBC驱动程序
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();

//设置数据库连接字符串
//strCon = "jdbc:odbc:Test_db";
strCon = "jdbc:microsoft:sqlserver://vially:1433;DatabaseName=GuestBook";

//连接数据库
//sqlCon = java.sql.DriverManager.getConnection(strCon,"sa","smallcat");

sqlCon = java.sql.DriverManager.getConnection(strCon,"sa","smallcat");

//创建SQL语句对象
sqlStmt = sqlCon.createStatement();

//获取记录总数
strSQL = "select count(*) from guestbook";

sqlRst = sqlStmt.executeQuery(strSQL);

//执行SQL语句并取得结果集
sqlRst.next();
//记录集刚打开的时候,指针位于第一条记录之前
intRowCount = sqlRst.getInt(1);

sqlRst.close();
//关闭结果集

//记算总页数
intPageCount = (intRowCount+intPageSize-1) / intPageSize;

//调整待显示的页码 if(intPage>intPageCount) intPage = intPageCount;

//设置获取数据SQL语句
strSQL = "select name,email,body from guestbook";

//执行SQL语句并取得结果集
sqlRst = sqlStmt.executeQuery(strSQL);
//将记录指针定位到待显示页的第一条记录上
i = (intPage-1) * intPageSize;

for(j=0;j<i;j++) sqlRst.next();
%>
<html>
<head>
<title>JSP数据库操作例程 - 数据分页显示 - JDBC连接MS sqlserver97/2000</title>
</head>
<body>
<p align=center>JDBC连接MS sqlserver97/2000 (带数据分页显示)</p>
<table border="1" cellspacing="0" cellpadding="0" width=600 align=center>
<%
//显示数据
i = 0;

while(i<intPageSize &amp;&amp;
sqlRst.next()){ %>
<tr>
<td>姓名:<%=sqlRst.getString(1)%></td>
<td>邮件:<a href=mailto:><%=sqlRst.getString(2)%></a></td>
</tr>
<tr>
<td colspan=2>留言内容:<%=sqlRst.getString(3)%></td>
</tr>
<tr>
<td colspan=2>&amp;nbsp;</td>
</tr>
<% i++;
} %>
<tr>
<td colspan=2 align=center>
第<%=intPage%>页 共<%=intPageCount%>页
<%if(intPage<intPageCount){%>
<a href="page.jsp?page=<%=intPage+1%>">下一页</a><%
}
%>
<%if(intPage>1){%>
<a href="page.jsp?page=<%=intPage-1%>">上一页</a><%
}
%>
</td>
</tr>
</table> </body>
</html>
<%
//关闭结果集
sqlRst.close();

//关闭SQL语句对象
sqlStmt.close();

//关闭数据库
sqlCon.close();
%>
 
把jdbc sql server 2000的三个jar文件复制到
sdk里目录下的jre/lib/ext里;
或者tocamt目录下的/common/lib里
 
还是不行啊,怎么办呢
 
呵呵,问题解决了,原来是我自己将1433断口给封了
给分了
 
后退
顶部