当前位置: 代码迷 >> Java Web开发 >> [求助]:各位大侠请帮帮小弟!!~~
  详细解决方案

[求助]:各位大侠请帮帮小弟!!~~

热度:342   发布时间:2005-10-04 12:51:00.0
[求助]:各位大侠请帮帮小弟!!~~
JSP在与sql server 2000 连接时我用的是下面的代码:

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
//try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=yg";
//yg为我的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//Statement stmt=conn.createStatement();  
String sql="select * from users";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
               <%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
//}catch(Exception e){
//out.println(e);
//}
%>
</body>
</html>
----------------解决方案--------------------------------------------------------
运行后出错:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)	org.apache.jsp._1_jsp._jspService(_1_jsp.java:90)	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)	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:512)	java.sql.DriverManager.getConnection(DriverManager.java:171)	org.apache.jsp._1_jsp._jspService(_1_jsp.java:54)	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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


----------------解决方案--------------------------------------------------------
你有jdbc 驱动没...
classpath设好了没...
----------------解决方案--------------------------------------------------------
jdbc 驱动和classpath都设好了!!
就是出现这样的错误:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
我搞了好几天了!!
----------------解决方案--------------------------------------------------------
try  ..catch   不要注释..
----------------解决方案--------------------------------------------------------
到查询分析器去看看你的用户名和密码是什么.你程序中用的是sa 和null.
----------------解决方案--------------------------------------------------------
请问一下JDBC驱动,还要下载??
哪里下载呀
----------------解决方案--------------------------------------------------------
网上收吧
这个不难吧
----------------解决方案--------------------------------------------------------
  相关解决方案