0

trying to connect to a free mysql database host which permits remote connections but i get this error:

No suitable driver found for jdbc:mysql://xx2-23-x1-2x1-172.compuxe-1.xmazonaws.com:3306

I use the code below.

 try{
      Class.forName("com.mysql.jdbc.Driver");
    System.out.println("Driver loaded");
    }
    catch(ClassNotFoundException e){
        System.out.println(e.getMessage());
    }
    try{
       String host = "jdbc:mysql://xx2-23-x1-2x1-172.compuxe-1.xmazonaws.com:3306/xxxxx";
        conn = DriverManager.getConnection(host,"xxxxx","xxxxx");
        System.out.println("Connection Established");
    }

Thanks in advance.

EDIT

Stack Trace appears below:

java.sql.SQLException: No suitable driver found for jdbc:mysql://xx2-23-x1-2x1-172.compuxe-1.xmazonaws.com:3306
    at java.sql.DriverManager.getConnection(DriverManager.java:604)
    at java.sql.DriverManager.getConnection(DriverManager.java:221)
    at DatabaseConnectivityModule.(DatabaseConnectivityModule.java:21)
    at UserFrontEnd.(UserFrontEnd.java:34)
    at UserFrontEnd$8.run(UserFrontEnd.java:399)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)
    at java.awt.EventQueue.access$000(EventQueue.java:102)
    at java.awt.EventQueue$3.run(EventQueue.java:662)
    at java.awt.EventQueue$3.run(EventQueue.java:660)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:671)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
  • Check this out:- http://stackoverflow.com/questions/5556664/how-to-fix-no-suitable-driver-found-for-jdbcmysql-localhost-dbname-error-w – Rahul Tripathi Aug 08 '13 at 16:19
  • 1
    the MySQL JDBC driver must be on the classpath. Your are catching the `ClassNotFoundException` then prints the message, do you see anything on the console? By the way, you should surround your complete code with one try-catch block. – Katona Aug 08 '13 at 16:20
  • I wil use the single try - catch block suggestion, the problem is that i don't see anything else popping up on the console. – Richard Kenneth Niescior Aug 08 '13 at 16:26
  • @RichardKennethNiescior put in a single try-catch then use e.printStackTrace() on the exception caught, that should print on the error stream the stack trace – Katona Aug 08 '13 at 16:36

1 Answers1

-1

You should make your code look like the follow:

try {
    Class.forName("com.mysql.jdbc.Driver");
    String host = "jdbc:mysql://xx2-23-x1-2x1-172.compuxe-1.xmazonaws.com:3306/xxxxx";
    conn = DriverManager.getConnection(host,"xxxxx","xxxxx");
} catch (Exception e) {
    e.printStackTrace();
}

Also verify that the MySQL JDBC library is in your classpath. The library can be downloaded from here.

Nic Raboy
  • 3,143
  • 24
  • 26