为什么我用JDBC连接不上数据库(SQLServer)

wangwei22 2007-04-22 02:07:57
我是在Xp(sp2)上安装的开发版的SQLServer 2000,Java开发环境配置的没有问题,jdbc驱动我也安装了,sqlserver我也更新到了sp4,只是有那个SQL Server 2000 Desktop Engine (MSDE) 组件安装不上,提示“指定的实例名称无效”,然后连接数据库时,老出现下面的错误:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /index.jsp:31
28: <%
29: //try{
30: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
31: Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev;User=jspdev;Password=jspdev");
32: Statement stmt=conn.createStatement();
33: ResultSet rst=stmt.executeQuery("select * from qx_users");
34: if(conn!=null)
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
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.index_jsp._jspService(index_jsp.java:112)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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.(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(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.index_jsp._jspService(index_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection refused: connect
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSConnection.(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(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.index_jsp._jspService(index_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.23
...全文
562 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangwei22 2007-05-08
  • 打赏
  • 举报
回复
搞定了谢谢各位
wangwei22 2007-04-22
  • 打赏
  • 举报
回复
我用telnet localhost 1433连接不上的
还有就是用netstat -an 看不到1433端口
不过我确实已经安装了sp4啊
不过在安装“SQL Server 2000 Desktop Engine (MSDE) 组件”时出了错
不会跟这个有关吧?
wangwei22 2007-04-22
  • 打赏
  • 举报
回复
sql的jdbc中的jar包已经放在tomcat的lib里面了啊,而且网站的WEB-INF里我也放了一份的
lanseliuying 2007-04-22
  • 打赏
  • 举报
回复
数据库拒绝访问
确定用户名和密码是否正确
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=你得数据库名";
String user="你得用户名,默认是sa";
String password="你得密码,默认是空";
Connection conn=DriverManager.getConnection(url,user,password);
chpinck 2007-04-22
  • 打赏
  • 举报
回复
sql的jdbc中的jar包有沒有放在tomcat的lib里面。
chpinck 2007-04-22
  • 打赏
  • 举报
回复
<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.sql.*"%>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=myflow";
String user="myflow";
String password="myflow";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
%>
<HTML>
<BODY>
<%
while(rs.next())
{
%>
內容:<%=rs.getString(2)%><BR>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</BODY>
</HTML>
看看你的sql配置有沒有問題!
jerrycccc2323 2007-04-22
  • 打赏
  • 举报
回复
没链接上数据库,你刚装完数据库一般默认用户名是sa,除非你改了,还有就是jdbc的三个架包拷贝到,lib下
ftiger 2007-04-22
  • 打赏
  • 举报
回复
http://dev.csdn.net/article/70/70360.shtm

Error establishing socket.
说明

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧