List:MySQL and Java« Previous MessageNext Message »
From:Shridhar Date:February 18 2003 10:01am
Subject:How to connect to a MySQL DB which is on a remote machine..
View as plain text  
Hi All,

How to connect to a MySQL db which is on a remote machine
I tried the , but i'm getting SQLException..
Please tell me where am i going wrong..

Thanks,
Shridhar..


The Code:
=======

  try
  {
   System.out.println("Hello ");
   Class.forName("org.gjt.mm.mysql.Driver");
   System.out.println("Class Loaded : ");
   String url = "jdbc:mysql://IPAddr_of_remote_machine/dbName";
   Connection dbCon = DriverManager.getConnection(url, "root", "");
   System.out.println("conn   : ");
   Statement vSt = dbCon.createStatement();
   System.out.println("stmt : ");
   String ReqStr = "select * from test_table";
   ResultSet vRs = vSt.executeQuery(ReqStr);
   while(vRs.next())
   {
    System.out.println(vRs.getString(1));
   }
  }
  catch(Exception e)
  {
   e.printStackTrace() ;
  }

Output :
======

Hello
Class Loaded :
java.sql.SQLException: Unable to connect to any hosts due to exception:
java.net.ConnectException: Connection timed out: connect
 at com.mysql.jdbc.Connection.createNewIO(Connection.java:1670)
 at com.mysql.jdbc.Connection.connectionInit(Connection.java:901)
 at com.mysql.jdbc.Driver.connect(Driver.java:311)
 at java.sql.DriverManager.getConnection(DriverManager.java:512)
 at java.sql.DriverManager.getConnection(DriverManager.java:171)
 at aa.main(aa.java:19)
Interactive Session Ended


Thread
How to connect to a MySQL DB which is on a remote machine..Shridhar18 Feb
  • Re: How to connect to a MySQL DB which is on a remote machine..raffi@dcit.com18 Feb
  • Re: How to connect to a MySQL DB which is on a remote machine..Shridhar19 Feb
    • Re: How to connect to a MySQL DB which is on a remote machine..raffi@dcit.com19 Feb
      • Re: How to connect to a MySQL DB which is on a remote machine..G. Wayne Kidd19 Feb
        • Re: How to connect to a MySQL DB which is on a remote machine..raffi@dcit.com19 Feb
    • Re: How to connect to a MySQL DB which is on a remote machine..Keith Knaide19 Feb
  • Re: How to connect to a MySQL DB which is on a remote machine..Shridhar20 Feb
Re: How to connect to a MySQL DB which is on a remote machine..bbonkosk19 Feb
  • RE: How to connect to a MySQL DB which is on a remote machine..George Pitcher19 Feb
    • RE: How to connect to a MySQL DB which is on a remote machine..Keith Knaide19 Feb