Skip to Main Content

New to Java

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!

SQLException: No suitable driver found

800965Feb 18 2011 — edited Feb 18 2011
Hi,

Can you help me out with this: I'm trying to get JDBC to work with this simple snippet:
package databasetest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
//import com.mysql.jdbc.Driver; //does not find the class(?)
import java.sql.Driver;

public class Main {

    public static void main(String[] args) {

        Connection conn = null;
        try {
            //DriverManager.registerDriver(new Driver() {});
            //System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=someuser&password=somepassword");

        } catch (SQLException ex) {
            // handle any errors
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
        }
    }
}
I get this output:
SQLException: No suitable driver found for jdbc:mysql://localhost/test?user=someuser&password=somepassword
SQLState: 08001
VendorError: 0
I'm not sure what to do next. I have set the CLASSPATH enivronment variable in the /etc/profile (it's a Mac) file to:
export CLASSPATH=$CLASSPATH://Applications/mysql-connector-j/mysql-connector-java-5.1.15-bin.jar 
How can I install the Driver correctly or what should I do basically to get it to work?

Thanks,

PR.
This post has been answered by abillconsl on Feb 18 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2011
Added on Feb 18 2011
5 comments
2,734 views