Communications link failure due to underlying exception:

bluesource <[email protected]> Wed, 2 Jan 2008 01:37:13 -0800 (PST)
Newsgroups gmane.comp.db.mysql.java
Message-ID <[email protected]>
Hi,

I'm trying to establish a connection to a database..
I have written code here whereby it creates a connection below but there is
problem at the line I put a '*****' in for some reason...
Do I need to set up a Database prior to this? If so, I did by running
command prompt and logged in and did CREATE DATABASE dbName and granted
privileges and such.

from DBInstaller.java

public class DBInstaller {
			
	public static void main(String[] args) {
		ConnectionInstaller con = new ConnectionInstaller();
		con.createConnection(con.DB_Name);	
	}
}



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/*
 * This Connection.java file is used to establish a connection to the
database.
 */

public class ConnectionInstaller {

	public final String DB_Name = "Video_Database";
	
	public ConnectionInstaller() {
		// TODO Auto-generated constructor stub
	}
	
	//Pre: DatabaseName
	//Post: Connection established to the database
	public Connection createConnection(String dbName){
		Connection con = null;
		String url = "jdbc:mysql://localhost:3307/";
		String user = "root";
		String pw = "";

		System.out.println("ESTABLISHING CONNECTION TO THE DATABASE");
		try{
                        //Put System.out.println("1"); so I can see where
the error is
			//Load the Driver you want to use
			//Class.forName creates an instance of a driver and registers it with
DriverManager
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("1");
	*****       con = DriverManager.getConnection(url+dbName, user, pw);
			System.out.println("1");
			System.out.println("Established Connection to the Video Database");
		}catch(Exception e){
			System.out.println(e.getMessage());
			System.out.println("Could not Establish Connection to Video Database");
			System.exit(0);			
		}		
		return con;	
	}
	public Connection createVideoDB(){
		return createConnection("");		
	}
	
	public void videoDBsetup(String dbName){
		Connection con = createVideoDB();		
		try{
			Statement s = con.createStatement();
			//more code will be written here later....
		}catch(Exception e){ }
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}
}

======================================================================

ESTABLISHING CONNECTION TO THE DATABASE
1
Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection refused:
connect
	at
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2641)
	at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
	at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at
Database.ConnectionInstaller.createConnection(ConnectionInstaller.java:38)
	at Database.DBInstaller.main(DBInstaller.java:33)


** END NESTED EXCEPTION **



Last packet sent to the server was 20 ms ago.
Could not Establish Connection to Video Database


======================================================================

Any help recieved would be much appreciated. I'm a first timer in creating
this....thanks :)
If there is any mistake I did from setting up DB....please provide
instructions on how I should have done (step-by-step) 


-- 
View this message in context: http://www.nabble.com/Communications-link-failure-due-to-underlying-exception%3A-tp14575527p14575527.html
Sent from the MySQL - Java mailing list archive at Nabble.com.


-- 
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/[email protected]