lensi
asked on
Cannot Connect to Remote Database Using Eclipse
HI iam using Eclipse 3.0.1 ans sqlexplorer_2.2.4. My Webhosting provider provided MYSQL4.0.1. Well iam tryiong to connect using SQLExporer using Eclipse.
I have entered following details
Name:: MyDBName
Driver :: MMMysqlSQL Driver
URL :: jdbc:mysql://MyWebName.com /
UserName :: myusername
Password :: mypassword
Iam getting an exception after some time like this::
Unable top Connect to any hosts due to exeption java.net.ConnectException. Connection timed out.......
What could be the problem?????
Regards
Lenin
I have entered following details
Name:: MyDBName
Driver :: MMMysqlSQL Driver
URL :: jdbc:mysql://MyWebName.com
UserName :: myusername
Password :: mypassword
Iam getting an exception after some time like this::
Unable top Connect to any hosts due to exeption java.net.ConnectException.
What could be the problem?????
Regards
Lenin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this function to connect
boolean EstablishConnection() {
String myUsername = "myusername";
String myPassword = "mypassword";
try {
// replace "com.mysql.jdbc.Driver" with your own driver
Class.forName( "com.mysql.jdbc.Driver" ).newInstance() ;
} catch ( Exception ex ) {
System.out.println( "DRIVER REGISTRATION EXCEPTION\n" + ex ) ;
// return false to communicate failure
return false ;
}
// try to connect to database
try {
/* The username and password for the database must be set here */
String strUserPass = "&user=" + myUsername + "&password=" + myPassword ;
String strPort = "" ; // default is :3306
// try to establish a connection
conn = DriverManager.getConnectio n("jdbc:my sql://MyWe bName.com" + strPort + "/" + strDatabase + "?autoReconnect=true" + strUserPass ) ;
return true;
} catch ( SQLException sqlex ) {
// split the error message on the tab characters and then display it
String[] sqlexLines = sqlex.toString().split( "\t" ) ;
System.out.println( "CONNECTION EXCEPTION\n" + sqlexLines[ 0 ] ) ;
for ( int k = 1 ; k < sqlexLines.length ; k++ ) {
System.out.println( "\n" + sqlexLines[ k ] ) ;
}
// return false to communicate failure
return false ;
}
}
boolean EstablishConnection() {
String myUsername = "myusername";
String myPassword = "mypassword";
try {
// replace "com.mysql.jdbc.Driver" with your own driver
Class.forName( "com.mysql.jdbc.Driver" ).newInstance() ;
} catch ( Exception ex ) {
System.out.println( "DRIVER REGISTRATION EXCEPTION\n" + ex ) ;
// return false to communicate failure
return false ;
}
// try to connect to database
try {
/* The username and password for the database must be set here */
String strUserPass = "&user=" + myUsername + "&password=" + myPassword ;
String strPort = "" ; // default is :3306
// try to establish a connection
conn = DriverManager.getConnectio
return true;
} catch ( SQLException sqlex ) {
// split the error message on the tab characters and then display it
String[] sqlexLines = sqlex.toString().split( "\t" ) ;
System.out.println( "CONNECTION EXCEPTION\n" + sqlexLines[ 0 ] ) ;
for ( int k = 1 ; k < sqlexLines.length ; k++ ) {
System.out.println( "\n" + sqlexLines[ k ] ) ;
}
// return false to communicate failure
return false ;
}
}
ASKER
Hi,
Guys Got it. Its a Firewal issue.
Lenin Chalasani
Guys Got it. Its a Firewal issue.
Lenin Chalasani
i think this problem comes if ur dbname does not exist.