Unable to connect to MySql from eclipse
Posted by: Abdul Raqeeb
Date: March 27, 2010 10:50PM

Hi,

I searched a number of threads and forums but was unable to find the reason for this issue. Please find my code belo.

import java.sql.Connection;
import java.sql.DriverManager;


public class MySql
{
/**
* @param args
*/
/**
* @param args
*/
/**
* @param args
*/
public static void main (String[] args)
{
Connection conn = null;

try
{
String userName = "root";
String password = "secret";
String url = "jdbc:mysql://locahost:3306/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
if(!conn.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");

}
catch (Exception e)
{
System.out.println(e.getLocalizedMessage());
}
}
}




I added the mysql connector in the build path of eclipse but it still doesn't work.
It gives Communication Link Failure Exception or sometimes com.mysql.jdbc.Driver
I am able to connect to the server thru the GUI tool of MySql. I created the dsn in windows with name test using the MySql driver.
Please help me out.

Options: ReplyQuote


Subject
Written By
Posted
Unable to connect to MySql from eclipse
March 27, 2010 10:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.