wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
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

I am having problem in getConnection(), i written DatabaseConnection class.
but it's compiling fine but while runing it's showing Exceptions.
I am using NetBeans 6 and Server tomcat 6.0.16. please help to solve this problem. I added jar file that is "mysql-connector-java-5.1.6-bin.jar" i added jar file in the folder C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.16\lib

I am new to coding please help me or give sugestions.............

import java.sql.*;
//import java.util.*;

* @author venu
public class DatabaseConnection {
public static Connection getConnection() {
Connection connection=null;
String driver= "com.mysql.jdbc.Driver";
String URL = "jdbc:mysql://mysql.local.com:3306/venu";
String username = "root";
String password = "root";
try {
if(driver == null || URL == null) {
throw new Exception("Driver class or Driver URL should not be null");
catch(Exception e) {
return connection;
public static void main(String args[])

Connection con = getConnection();
System.out.println("got connection");
System.out.println("got connection");
catch(Exception e)

/* Exceptions */

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.venu.login.common.DatabaseConnection.getConnection(DatabaseConnection.java:27)
at com.venu.login.common.DatabaseConnection.main(DatabaseConnection.java:40)
Caused by: java.net.ConnectException: Connection timed out: 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)
got connection
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
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.java:253)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)
... 7 more
at com.venu.login.common.DatabaseConnection.main(DatabaseConnection.java:42)
BUILD SUCCESSFUL (total time: 22 seconds)

Venu J
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 9921

Caused by: java.net.ConnectException: Connection timed out: connect

Are you sure that the connection URL that you are using is correct? Is the DB server listening on that address and port?

[My Blog] [JavaRanch Journal]
venu jayaram

Joined: Mar 11, 2008
Posts: 27
Ya i am using correct URL and port number.

In Netbeans 6 in service tab database it's showing the tables name using same URL and Port number with database Name


i don't no what's the problem when i click on errros that will call the
database API it's showing error on getConnection method

Please tell how to solove this problem.
subject: JDBC Connection problem
Similar Threads
I can not for the life of me figure out what is causing this
Removing Eclipse Ganymede
problems connecting to remote db thru jdbc app
Problem with connecting to database
JDBC Connection Problem