我用如下的jsp文件连接sqlserver数据库,
<%@ 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=db_board ";
//pubs为你的数据库的
String user= "sa ";
String password= " ";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql= "select * from tb_User ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为: <%=rs.getString(1)%>
您的第二个字段内容为: <%=rs.getString(2)%>
<%}%>
<%out.print( "数据库操作成功,恭喜你 ");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
不知为什么出现如下的错误,是不是我的sqlserver数据库有问题啊?已打了sp4补丁,tomcat\lib下也有jdbc驱动,用的是1433端口,
在dos下:
ping (服务器IP地址ip)
连接正常...
或
ping (服务器名)
连接正常...
telnet <服务器IP地址> 1433
正在连接到localhost...不能打开到主机的连接, 在端口 1433: 连接失败
请问大家一下这可能是什么问题啊!
下面是jsp读取sqlserver数据库出现的错误:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.testsqlserver_jsp._jspService(testsqlserver_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)