Sign-up....

~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

我已经将mssqlserver.jar,msutil.jar,msbase.jar3个jar文件也可以放在 WEB-INF/lib/目录下,我系统是window xp ,数据库为SQLserver2000个人版:

连接数据库程序如下:

<%@ page contentType="text/html;charset=gb2312"%>

<%@ page import="java.sql.*"%>

<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="19837020";

Connection conn= DriverManager.getConnection(url,user,password);

Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

String sql="select * from test";

ResultSet rs=stmt.executeQuery(sql);

while(rs.next()) {%>

您的第一个字段内容为:<%=rs.getString(1)%>

您的第二个字段内容为:<%=rs.getString(2)%>

<%}%>

<%out.print("数据库操作成功,恭喜你");%>

<%rs.close();

stmt.close();

conn.close();

%>

</body>

</html>

出现以下异常(不知道为什么?):

exception

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)

org.apache.jsp.sql_jsp._jspService(org.apache.jsp.sql_jsp:83)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)

com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)

com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)

com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)

com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)

java.sql.DriverManager.getConnection(DriverManager.java:525)

java.sql.DriverManager.getConnection(DriverManager.java:171)

org.apache.jsp.sql_jsp._jspService(org.apache.jsp.sql_jsp:52)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.6 logs.

[2963 byte] By [msdn] at [2007-8-14 22:11:20]
# 1 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

接上,我用--账号:sa 和 密码:19837020--是可以登录数据库的,既然这样了,但是真的想不出错在哪里了

CJamie at 2005-7-8 16:04:49 >
# 2 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

第一保证你的登陆模式是 混合模式 这个在服务器属性里面可以看到

选 “windows 和sql server”反正就是选这个 具体名字我忘了

如果上面还是不行 你可以将连接端口由1433 改成其他的端口(注意不要于其他程序的端口发生冲突)

也是在属性里面 点 网络设置 tcp/ip 改掉1433

你的连接的代码 jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs 也要改成相同的端口

祝好运

ricky921 at 2005-7-8 16:43:14 >
# 3 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

打sp4补丁

feihn at 2005-7-8 16:52:33 >
# 4 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

在连接的数据库建同样的用户(不是sqlserver的用户,是数据库的用户)

jadkyin at 2005-7-8 16:54:29 >
# 5 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

==================

微软的JDBC驱动应该是不支持创建滚动Statement的

jtds可以。

你直接Statement stmt=conn.createStatement()看看会不会报错

tiannet at 2005-7-8 17:09:36 >
# 6 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

初次接触SQLserver2000,我改了用户和密码了,端口号也改了,还是不行

CJamie at 2005-7-8 17:13:12 >
# 7 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

firewall??

pioneer_csdn at 2005-7-8 18:05:48 >
# 8 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

这个我也碰到过,帮你UP

dobly at 2005-7-8 18:11:24 >
# 9 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

反正我是把端口改了就可以了!!!

记住我上面说的 有两个位置的端口都要改

一个是你的程序中的端口号

一个是sql server中的端口号

ricky921 at 2005-7-8 19:03:53 >
# 10 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

试以下:

1、打SQL SERVER补丁,这个问题经常在打补丁后好了

2、系统重装,这样的情况也的确存在。我就碰到过XP下JSP程序无法在网络上发布,但自己机器上OK

3、环境变量设置好了吗?

henbane at 2005-7-8 21:48:55 >
# 11 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

谢谢各位了,我是经采用sun.jdbc.odbc.JdbcOdbcDriver连接桥才行的,至于直接用com.microsoft.jdbc.sqlserver.SQLServerDriver这个还不行,不知道为什么?要打补丁的吗?

CJamie at 2005-7-8 22:05:58 >
# 12 Re: ~~~~~JSP连接SQL2000出错,请大侠们帮忙解决~~~~

winxp sp2好像要打补丁。

woolceo at 2005-7-8 23:04:52 >

Web

All Classified