Remote Database - java

I tried creating an app in java that works with a remote database. The apps works fine on a local database. I have included the the port number as well. I am scared that it may be the IP address I am using.
I thought to myself there may be hundreds if not thousands of pc's around the world with the same IP as mine... and how does the Internet see which one I am, or stay secure about it. I am sure you don't give the remote access the IP of you computer of you home network, but I may be wrong... I honestly don't know.
This is my function.
public void db() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection myCon = DriverManager.getConnection("jdbc:mysql://IPOfWebSite:3306/DatabaseName", "UserName", "Password");
System.out.println("Connected");
myCon.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
On the Remote DB I have added my public IP address, but still received this error
"C:\Program Files\Java\jdk1.8.0_25\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.3\bin" -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;H:\Java Dev\Simple_java_DB\out\production\Simple_java_DB;H:\Java Dev\Simple_java_DB\mysql-connector-java-5.1.35\mysql-connector-java-5.1.35\mysql-connector-java-5.1.35-bin.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain Main
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1038)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2237)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2270)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2069)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Main.db(Main.java:24)
at Main.main(Main.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297)
... 21 more
Any help will be great. By the way I did check my firewall... it should allow the port to receive and sent.

MySQL does by default only listen to the local interface (loopback). So you can only reach it from the local machine.
To change this, adapt the MySQL conf:
[mysqld]
bind-address=YOUR-SERVER-IP
Also, make sure the skip-networking configuration is commented out or not present.
More details here.

1) Make sure you're adding your external IP, not your internal network IP (192.168.x.x).
Go to: https://www.whatismyip.com/ and use that IP for whitelisting your IP in the remote DB's firewall and/or access restrictions.
2) Make sure your mysql user is set up with the correct host, either 'user'#'your-external-ip' or 'user'#'%' (to allow that user to connect from any IP).
3) Make sure your my.conf is set up to allow remote connections. Make sure you're not binding to 127.0.0.1, instead temporarily do:
bind-address = 0.0.0.0;
You should set this to your server's actual IP, but 0.0.0.0 will work for any IP and should just be used temporarily to verify that this is your problem. Long term it could pose a security risk to leave it as 0.0.0.0.
Also make sure that you're not skipping networking. Make sure this line is commented out (with a # in front of it):
# skip-networking

Related

mysql communication link failure on 2 laptops

I have made a software, I have made the mysql database on the different laptop, and the software on different laptop, means i have 2 laptops one has software and one has database and both are connected with internet wire. now I am connecting my software with the database which is installed on different laptop but I get a communication failure link. I have given the ip address of the server laptop, but yet i get the error, please tell me how to resolve this issue, the code is here.
private static void init()throws Exception{
String url="jdbc:mysql://169.254.96.182:3306/content_management_system";
String user="root";
String password="oracle";
con=DriverManager.getConnection(url, user, password);
System.out.println("connection successfull");
}//end method
and the errror is
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2189)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2222)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
By default, the port 3306; which you are using to route the connection to your database, will be closed - or at least, blocked from any outside connections.
You'll need to open this port; and potentially add port forwarding to ensure any outside connections are directed properly.
Look up how to open ports and check out this link on port forwarding.
As mentioned in the comments you can also use the command PING 169.254.96.182 to check if a connection can be established!
Also if you do open the port, unless you have strict security measures in place; you should remove your IP from this question as you're basically giving us all access!

failure to connect to mysql from java locally while remote connection works

I have the following situation:
I can
connect to my mysql database via the command line tool mysql, both from the local machine and a remote host
connect from a small java test program from the remote host
I can not
connect from that same small java test program from the local machine
The test code is basically the same as in this question and I followed all the suggestions given there to solve my problem with no avail. I have tried the following connection strings:
jdbc:mysql://localhost/database
jdbc:mysql://localhost:3306/database
jdbc:mysql://127.0.0.1/database
jdbc:mysql://hostname/database
all resulting in the same error message. On the remote machine I could use the fourth alternative with no problem.
I am running a mysql-5.5 server. The remote uses java version "1.7.0_101" and the local machine has java version "1.6.0_38".
Here is the error message when I run my java program on the local machine:
Connecting to database...
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:534)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:688)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1094)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2337)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:534)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:615)
at java.sql.DriverManager.getConnection(DriverManager.java:195)
at FirstExample.main(FirstExample.java:22)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2540)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:612)
... 16 more
Goodbye!
I just realized that mysql -u user database would work, but not mysql -u user -h 127.0.0.1 database, so it turned out I had an error in my /etc/hosts.allow file. Problem solved!

Unable to create connection between two PC on LAN (windows, RabbitMQ)

I am trying to send messages between two local PC (Windows OS). I have connected to these PC using LAN connection. The RabbitMQ server is installed on 10.100.94.25 PC. I am trying to create a connection from 10.100.94.28 PC. I have ping to my rabbit MQ server PC (10.100.94.25) from Client PC (10.100.94.28) using windows command prompt. It was successful. But, when I try to create a connection from code, it is not working. Please check my code and error log bellow. the error is telling me that "timeout error". what should I do?
I have successfully sent and received a message from the same PC. That means, when I use localhost as host, it works perfectly. Then what is the tiny touch I am missing here for remote access?
connectionFactory = new ConnectionFactory();
connectionFactory.setUsername("shoshi");
connectionFactory.setPassword("shoshi");
connectionFactory.setHost("10.100.94.25");
connectionFactory.setPort(5672);
connection = connectionFactory.newConnection(); // this is 451 number line
error:
May 01, 2016 6:00:35 PM com.chat.UI initRabbitMQ
SEVERE: null
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:714)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:760)
at com.chat.UI.initRabbitMQ(UI.java:451)
at com.chat.UI.<init>(UI.java:48)
at com.chat.UI$8.run(UI.java:405)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
I was guessing that the 5672 port is open or not. Or the firewall is blocking it or not. thanks to cantSleepNow and Thomas for their instruction.
So, what I have done? I just check the port number using telnet. the command is telnet IP_ADDRESS PORT_NUMBER. if telnet is not recognized as a command, then you have to enable it. follow the instruction bellow:
To install Telnet, please follow these instructions:
Click Start then select Control Panel.
Select Programs and Features.
Select Turn Windows features on or off.
Select the Telnet Client option.
Click OK.
or, follow this link
I was able to get a response by using telnet localhost 5672 command. but not with telnet 10.100.94.25 5672 command.
Also, from THIS POST I get that:
connection refused means that nothing is running on that port
accepted means that something is running on that port
timeout means that a firewall is blocking access
And my error log says that java.net.ConnectException: Connection timed out: connect
So, now I am sure that it is a firewall issue.
Then I just open erlang for remote access by following THIS TUTORIAL. And now it is working.
To know your PC's IP adress just type ipconfig using CMD.
This is most probably a (Windows) firewall issue, make sure that connections to that port are allowed.
With my ActiveMQ setup, the way I usually check my connection is:
I have a tester EJB which subscribes to a topic on the ActiveMQ system. I start my ActiveMQ system, and then run the EJB on my own server on another system. If the connection is all fine, then this EJB shows up as a consumer on the ActiveMQ dashboard. This method ensures connection setup without any nitty gritty problems with setting up the connection. Since you ping is working, this test should ideally go through successfully.
If success, you need to make sure your producer is working fine.
If failure, you know for sure that the connection is not setup properly.

Connect to the MySQL server from another PC (from java application)

I realized an java application that connects to MySQL.
when i make my ip adress of my pc in the navigator of another pc in same local network ,I access to phpMyadmin and Wamp.
When i make 127.0.0.1 on the same pc (Wamp install) I connect to 127.0.0.1 from my java application and it works .
but the problem when I put my ip address in my java application either from my pc or from another pc in same local network , I can not manage to connect .
this is my file of configuration in the java application:
db.user=root
db.password=
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://192.168.1.59:3306/testfournisseur
Is there a manipulation to do?
This is the errors appear when i connect to the database:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 1 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:666)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1069)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
... 72 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2431)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:590)
... 74 more
I'm unfamiliar with MySQL on Windows but the most common reason I see for being unable to connect is that the bind-address in my.cnf is set to 127.0.0.1, if you change this to 0.0.0.0 or another accessible address then it should work fine.
I also noticed you specify port 80 in your properties example, MySQL runs on 3306 by default so changing the port to that (or omitting it) may work.
Edit: Windows' built-in firewall may be blocking the connection so it's definitely worth checking out.

Tomcat unable to connect to mysql through JDBC connector

I have an web application that I was trying deployed on a remote windows 2003 server with java6, tomcat6 and mysql5.5. After deploying application when I hit the application url I am getting following error. I did some google and found some link which says to change localhost in connection string to 127.0.0.1 but that did not worked, some link says to check connection string so I created a simple java class on same windows machine to test the connection string, usename and password. When I ran that class it worked fine without any error but when I am running web application which uses same connection string and username and password it is throwing the error. There are also some links which advice to modify my.ini of mysql but I did not find any my.ini in mysql installation directory.
I am not getting any clue to deal with this error so could you please guide me on this. Full stack trace is as below
INFO: Server startup in 2832 ms
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai
lure
The last packet sent successfully to the server was 0 milliseconds ago. The driv
er has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1
117)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:350)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2408)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2
445)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2230)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:334)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.adxchange.utils.DBConnectionSingleton.getConnection(DBConnectionS
ingleton.java:28)
at com.adxchange.utils.ADXchange.getStates(ADXchange.java:402)
at org.apache.jsp.homepage_jsp._jspService(homepage_jsp.java:252)
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:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
13)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatc
her.java:416)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcesso
r.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.pr
ocess(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:16
75)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.ja
va:259)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
... 38 more
getStates: Error in database connection
could it be some permission issue?
EDIT:
I also created CLASSPATH variable in system variables and added java\lib and tomcat\lib path in it but still no result.
Sorry friends to put you in effort of looking and answering my question but I found the solution. Actually it is my silly mistake that I have used .properties file for all db and other changeable things and the problem was that I was modifying wrong properties file. It is so embarrassing that I created a mess for simple thing. Anyway thanks a lot that you guys helped.
I think you may need to take a look at the tomcat config, a usual error on these modern setups is that either mysql or tomcat is trying to connect using IPV6 so you need to make sure you only listen on IPV4 for it to work.
I'd also see if there's a firewall between your Tomcat and MySQL. You might need a firewall rule to open up the port for MySQL.
You can tell by pinging the MySQL IP address from the Tomcat server. If you can't ping, your app can't either.
The host should be the name of the MySQL server, not localhost.
Is the database running on the same box as Tomcat? That's not a good design.
Are you sure MySQL is running? Can you log into the admin console and access the database that your Java app needs to get to? If yes, does the Java app use appropriate credentials? (Please don't tell me that you gave it the admin root access.)

Categories