0

您好我必须使用soap webservices开发带有mysql数据库连接的android登录。

它成功地工作了我的(localhost/phpmyadmin

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/androidlogin","root","");

但它在我的开发网站上不起作用:( dev.www.com/phpmyadmin

Connection con = DriverManager.getConnection("jdbc:mysql://dev.www.com:3306/login","mm2","mm5");

我使用了上面的代码意味着出现以下错误。请告诉我如何解决这个错误。

出现以下错误:

  java.sql.SQLException: Unable to connect to any hosts due to exception:      java.net.SocketException: java.net.ConnectException: Operation timed out

 ** BEGIN NESTED EXCEPTION ** 

 java.net.SocketException
 MESSAGE: java.net.ConnectException: Operation timed out

 STACKTRACE:

 java.net.SocketException: java.net.ConnectException: Operation timed out
 at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:143)
 at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
 at com.mysql.jdbc.Connection.createNewIO(Connection.java:1805)
 at com.mysql.jdbc.Connection.<init>(Connection.java:452)
 at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
 at java.sql.DriverManager.getConnection(DriverManager.java:582)
 at java.sql.DriverManager.getConnection(DriverManager.java:185)
 at com.xcart.Login.authentication(Login.java:16)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
 at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
 at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
 at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
 at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
 at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
 at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:680)


  ** END NESTED EXCEPTION **


  at com.mysql.jdbc.Connection.createNewIO(Connection.java:1875)
  at com.mysql.jdbc.Connection.<init>(Connection.java:452)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
  at java.sql.DriverManager.getConnection(DriverManager.java:582)
  at java.sql.DriverManager.getConnection(DriverManager.java:185)
  at com.xcart.Login.authentication(Login.java:16)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
  at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
  at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
  at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
  at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
  at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
  at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  at java.lang.Thread.run(Thread.java:680)
4

1 回答 1

1

这不是代码问题。这是你的环境中的东西,所以我不确定这里有多少人可以帮助你。这里有一些提示。异常消息是:

java.net.ConnectException: Operation timed out

这排除了一些事情。如果您能够访问主机 www.dev.com 但 mysql 没有运行,您将获得java.net.ConnectException: Connection refused. 如果您输入错误的地址(例如 www.dev.comm),您会得到java.net.UnknownHostException: <host name>.

不幸的是,您遇到了超时错误。这意味着主机名已成功解析为地址,但是当您尝试连接到该地址时,您绝对没有得到计算机的任何响应。这通常意味着两件事之一:

  • 有人关掉电脑
  • 您和计算机之间打开了防火墙,并且防火墙不允许端口 3306 上的 tcp 连接。

我猜是防火墙。祝你好运。希望这可以帮助。

于 2012-10-27T04:14:54.453 回答