永发信息网

jsp jdbc连接数据库出错

答案:4  悬赏:0  手机版
解决时间 2021-06-07 03:19
  • 提问者网友:蓝莓格格巫
  • 2021-06-06 15:30

错误提示如下:

Using CATALINA_BASE: C:\Users\Hao\.netbeans\6.7\apache-tomcat-6.0.18_base
Using CATALINA_HOME: C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.18
Using CATALINA_TMPDIR: C:\Users\Hao\.netbeans\6.7\apache-tomcat-6.0.18_base\temp
Using JRE_HOME: C:\Program Files\Java\jdk1.6.0_05
2009-12-7 0:44:41 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_05\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\oracle\product\10.2.0\db_1\bin;C:\Program Files\360\360se;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Windows7Master;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static.;C:\Program Files\Java\jdk1.6.0_05\bin;C:\Windows\WebCallCtrl;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\ASUS Security Center\ASUS Security Protect Manager\bin;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\
2009-12-7 0:44:41 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8084
2009-12-7 0:44:41 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 484 ms
2009-12-7 0:44:41 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2009-12-7 0:44:41 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.18
2009-12-7 0:44:41 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8084
2009-12-7 0:44:41 org.apache.jk.common.ChannelSocket init
信息: Port busy 8009 java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
2009-12-7 0:44:41 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8010
2009-12-7 0:44:41 org.apache.jk.server.JkMain start
信息: Jk running ID=1 time=0/31 config=null
2009-12-7 0:44:41 org.apache.catalina.startup.Catalina start
信息: Server startup in 536 ms
2009-12-7 0:44:42 org.apache.catalina.core.StandardContext start
信息: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/ConnEx] has already been started
com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.NoRouteToHostException: No route to host: connect
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at db.Conn.<init>(Conn.java:26)
at org.apache.jsp.saveAdd_jsp._jspService(saveAdd_jsp.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
2009-12-7 0:47:21 org.apache.catalina.core.StandardContext reload
信息: Reloading this Context has started
com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at db.Conn.<init>(Conn.java:26)
at org.apache.jsp.saveAdd_jsp._jspService(saveAdd_jsp.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

附图:

使用的测试代码如下:

package test;

import java.sql.*;

public class TestJDBC {

public static void main(String[] srg) {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//加载JDBC驱动
String dbURL = "jdbc:sqlserver://10.1.43.154:1433; DatabaseName=db_shop"; //请修改数据库名称
//连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "1234"; //密码
Connection conn;
try {
Class.forName(driverName);
conn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!
} catch (Exception e) {
e.printStackTrace();
}
}
}

请问就上述问题,我该怎么解决?使用的数据库是SQL2005,操作系统WIN7.谢谢!

最佳答案
  • 五星知识达人网友:三千妖杀
  • 2021-06-06 16:29

String dbURL = "jdbc:sqlserver://10.1.43.154:1433; DatabaseName=db_shop";


中IP 10.1.43.154 是不是链接的服务器IP 啊 服务器的防火强是不是开着呢 添加 例外(端口1433)


全部回答
  • 1楼网友:冷風如刀
  • 2021-06-06 19:24

你电脑的端口是1433?你改过没?

  • 2楼网友:爱难随人意
  • 2021-06-06 18:24
win7操作系统中使用2005要打sp3的补丁,你打了没有?
  • 3楼网友:摆渡翁
  • 2021-06-06 16:54

Tcp/Ip 没有启用吧 在sql server 2005中有个配置工具选择sql server configuration manager

有个sql server 2005 网络配置 选中mssqlserver双击 有个Tcp/Ip 打开

把协议中已启用改为是 IP地址中Ip动态端口已启用改为是

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯