I want to connect to the database mysql .
I am using Type IV driver Connector/J.
How to connect to the database.

When i load the driver class its working after that i get this error


SQL Exception :Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused: connect

STACKTRACE:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.<init>(Socket.java:365)
at java.net.Socket.<init>(Socket.java:207)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.ja
va:173)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:268)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2745)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:285)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at myjdbc1.main(myjdbc1.java:20)


** END NESTED EXCEPTION **

Last packet sent to the server was 15 ms ago. 08S01 0

Is the database running? Is it running on port 3306? Is there a firewall active blocking the port? Are you attempting to connect to the right host? Are you attempting to connect to 3306? Are you using the correct tablename in the connection url? Is the username and password correct? Is MySQL configured to allow that user, with that password, to connect from where the user is attempting to connect from?

I think that pretty much covers the possibilites.

Thanks!Ur Qns help me to find solution

Very good. It has been awhile since a new poster here has been willing to work through his own problem. Good Job.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.