Link to home
Start Free TrialLog in
Avatar of lensi
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
Avatar of vsubram2
vsubram2

is ur dbname is correct .MyDBName.
i think this problem comes if ur dbname does not exist.
ASKER CERTIFIED SOLUTION
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.getConnection("jdbc:mysql://MyWebName.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 ;
    }
   
  }
Avatar of lensi

ASKER

Hi,

Guys Got it. Its a Firewal issue.

Lenin Chalasani