wood burning stoves*
The moose likes JDBC and the fly likes JDBC Connection Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connection Problem " Watch "JDBC Connection Problem " New topic

JDBC Connection Problem

venu jayaram

Joined: Mar 11, 2008
Posts: 27
Hi friends,

I written one JDBC connection class. While running it's showing Exception.
i am using netbeans6.1 and jboss4.0.4 server. i added the driver also that is my-connector-java-5.1.

please help me to solve this problem

Exception are

com.mysql.jdbc.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.myapp.struts.Database.getConnection(Database.java:25)
at com.myapp.struts.Database.main(Database.java:36)
got connection
Caused by: java.net.UnknownHostException: mysql.local.com: mysql.local.com
at java.net.InetAddress.getAllByName0(InetAddress.java:1128)
at java.net.InetAddress.getAllByName0(InetAddress.java:1098)
at java.net.InetAddress.getAllByName(InetAddress.java:1061)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:243)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)
... 7 more
at com.myapp.struts.Database.main(Database.java:38)
BUILD SUCCESSFUL (total time: 20 seconds)
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You have defined a JDBC URL that will try to connect the the DNS mysql.local.com. I'm guessing this doesn't exist. Shouldn't it be "localhost"?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
venu jayaram

Joined: Mar 11, 2008
Posts: 27
Then please tell me what have to do, I want to interact with database using JDBC through Struts application.. please asap...

Thanks and Regards
Venu J
Peter Johnson

Joined: May 14, 2008
Posts: 5823

What is the name of the host running MySQL? Change the database URL to use that host name (instead of "mysql.local.com"). If the MySQL database is running on the same host as your code, then use:

String URL = "jdbc:mysql://localhost:3306/venu";

JBoss In Action
venu jayaram

Joined: Mar 11, 2008
Posts: 27
thank you very Peter Johnson
jQuery in Action, 2nd edition
subject: JDBC Connection Problem