This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes JDBC Connection Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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(
at com.mysql.jdbc.ConnectionImpl.createNewIO(
at com.mysql.jdbc.ConnectionImpl.<init>(
at com.mysql.jdbc.ConnectionImpl.getInstance(
at com.mysql.jdbc.NonRegisteringDriver.connect(
at java.sql.DriverManager.getConnection(
at java.sql.DriverManager.getConnection(
at com.myapp.struts.Database.getConnection(
at com.myapp.struts.Database.main(
got connection
Caused by:
at com.mysql.jdbc.StandardSocketFactory.connect(
at com.mysql.jdbc.MysqlIO.<init>(
at com.mysql.jdbc.ConnectionImpl.createNewIO(
... 7 more
at com.myapp.struts.Database.main(
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 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: 5852

What is the name of the host running MySQL? Change the database URL to use that host name (instead of ""). 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
I agree. Here's the link:
subject: JDBC Connection Problem
It's not a secret anymore!