This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connection Problem " Watch "JDBC Connection Problem " New topic
Author

JDBC Connection Problem

venu jayaram
Greenhorn

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


init:
deps-module-jar:
deps-ear-jar:
deps-jar:
compile-single:
run-main:
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
java.lang.NullPointerException
at com.myapp.struts.Database.main(Database.java:38)
BUILD SUCCESSFUL (total time: 20 seconds)
Paul Sturrock
Bartender

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
Greenhorn

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
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

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
Greenhorn

Joined: Mar 11, 2008
Posts: 27
thank you very Peter Johnson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Connection Problem
 
Similar Threads
mysql connection problem
JDBC Connection problem
Removing Eclipse Ganymede
Help: Connecting MySQL Database to JTable
Problem with connecting to database