yannifan
March 31st, 2011, 05:23 AM
Hello
Im trying to connect MYSQL db using Java where my SQL db is on localhost.
Im facing some issues regarding communication link failure.
Program :
public testfile() throws ClassNotFoundException, SQLException{
Connection connection = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://localhost/rts?user=root&password=password");
System.out.println("Connected");
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if(connection != null)
connection.close();
}
}
Stack trace :
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection refused
STACKTRACE:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Abstrac tPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress( AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractP lainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:235)
at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager .java:620)
at java.sql.DriverManager.getConnection(DriverManager .java:222)
at test.testfile.<init>(testfile.java:18)
at test.mainfile.main(mainfile.java:9)
** END NESTED EXCEPTION **
Last packet sent to the server was 1 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2847)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager .java:620)
at java.sql.DriverManager.getConnection(DriverManager .java:222)
at test.testfile.<init>(testfile.java:18)
at test.mainfile.main(mainfile.java:9)
Telnet output :
telnet localhost 3306
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
Package/Software Info :
Eclipse Java EE IDE for Web Developers.
Version: Helios Service Release 1.
JDK6
Connector/J version 5.0.8
Ubuntu : Ubuntu 10.04 LTS- the Lucid Lynx
I have tried few things but it doesn't work ::
1. I changed port in my.cnf but no effect, I changed to 3312
same err repeats and telnet shows as follows :
shreya@shreya-laptop:~$ telnet localhost 3306
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
shreya@shreya-laptop:~$ telnet localhost 3312
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
nmap output :
shreya@shreya-laptop:~$ nmap localhost -p 3306
Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-31 09:45 IST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE
3306/tcp closed mysql
Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds
shreya@shreya-laptop:~$ nmap localhost -p 3312
Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-31 09:45 IST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE
3312/tcp open unknown
Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
2. I tried putting entry in hosts.allow but no effect
3. I have tried reinstalling mysql. Insertion of data through mysql prompt and c program works perfectly but not through java code.
4. I tried adding rules in ip tables still it doesnt help
5. I have tried different combinations of url string. I have also tried different versions of eclipse and Connector/J jar file(latest 5.1.15)
Please help
Thank you
Im trying to connect MYSQL db using Java where my SQL db is on localhost.
Im facing some issues regarding communication link failure.
Program :
public testfile() throws ClassNotFoundException, SQLException{
Connection connection = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://localhost/rts?user=root&password=password");
System.out.println("Connected");
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if(connection != null)
connection.close();
}
}
Stack trace :
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection refused
STACKTRACE:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Abstrac tPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress( AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractP lainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at java.net.Socket.<init>(Socket.java:392)
at java.net.Socket.<init>(Socket.java:235)
at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager .java:620)
at java.sql.DriverManager.getConnection(DriverManager .java:222)
at test.testfile.<init>(testfile.java:18)
at test.mainfile.main(mainfile.java:9)
** END NESTED EXCEPTION **
Last packet sent to the server was 1 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2847)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager .java:620)
at java.sql.DriverManager.getConnection(DriverManager .java:222)
at test.testfile.<init>(testfile.java:18)
at test.mainfile.main(mainfile.java:9)
Telnet output :
telnet localhost 3306
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
Package/Software Info :
Eclipse Java EE IDE for Web Developers.
Version: Helios Service Release 1.
JDK6
Connector/J version 5.0.8
Ubuntu : Ubuntu 10.04 LTS- the Lucid Lynx
I have tried few things but it doesn't work ::
1. I changed port in my.cnf but no effect, I changed to 3312
same err repeats and telnet shows as follows :
shreya@shreya-laptop:~$ telnet localhost 3306
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
shreya@shreya-laptop:~$ telnet localhost 3312
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
nmap output :
shreya@shreya-laptop:~$ nmap localhost -p 3306
Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-31 09:45 IST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE
3306/tcp closed mysql
Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds
shreya@shreya-laptop:~$ nmap localhost -p 3312
Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-31 09:45 IST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE
3312/tcp open unknown
Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
2. I tried putting entry in hosts.allow but no effect
3. I have tried reinstalling mysql. Insertion of data through mysql prompt and c program works perfectly but not through java code.
4. I tried adding rules in ip tables still it doesnt help
5. I have tried different combinations of url string. I have also tried different versions of eclipse and Connector/J jar file(latest 5.1.15)
Please help
Thank you