How do I check to see if I have JDBC installed on my system?

Viewed 580

I how does one check to see whether or not they have JDBC connector for mySQL installed in Mac OS?

2 Answers

You need to execute Class.forName("com.mysql.jdbc.Driver") inside a try-catch block in order to confirm if the MySQL JDBC driver is in the classpath or not. If it won't be found in the classpath, ClassNotFoundException will be thrown which you can capture and show an error message as shown below:

try {
    Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
    System.out.println("Error: MySQL JDBC driver not found.");
}

You can try to instantiate the mysql jdbc driver class":

try {
        // The newInstance() call is a work around for some
        // broken Java implementations
        Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (Exception ex) {
            // handle the error
    }
Related