Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.sql.SQLException: No suitable driver problem

843859Mar 5 2008 — edited Dec 30 2009
Hello all.

Firstly, i am new to programming java apps that connect to SQL databases.

I have set up a MySQL server on my computer, which i can successfully access through my command prompt on my pc (so i know its up and running). Now im trying to create a simple java program which connects to the sql database, and simply lists the contents of the table in question. However, when running this program i recieve this exception:

java.sql.SQLException: No suitable driver

I have thoroughly researched this problem on the internet, with many people saying that i have not installed the j/connector driver correctly. My j/connecter driver file is in C:\Program Files\JAVASQL\mysql-connector-java-3.0.17-ga-bin.jar . My Environmental Variable CLASSPATH in windows reads: ".;C:\Program Files\Java\jre1.5.0_03\lib\ext\QTJava.zip; C:\Program Files\JAVASQL\mysql-connector-java-3.0.17-ga-bin.jar", so i am pretty sure i have done everything correctly with reguards to installing the connector.

My program code is as follows:

   import java.sql.*;

    class TestSqlConnect
   {
   
       public static void main (String[] args)
      {
      

         try
         {
         
            Connection sqlConnection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/myDatabaseName","root","mypassword");
            Statement sqlStatement = sqlConnection.createStatement();
            ResultSet sqlResult = sqlStatement.executeQuery("SELECT * FROM Rooms");
         
            while (sqlResult.next())
            {
               System.out.println(sqlResult.getString("name"));
            }
            sqlStatement.close();
         
         }
             catch (Exception e)
            {
               System.out.println(e.toString());
            }	      
      }
   
   
   }
Note i have also tried the url "jdbc:mysql://localhost/myDatabaseName" and still get the same problem.

Any help would be greatly appreciated. cheers.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 27 2010
Added on Mar 5 2008
8 comments
196 views