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.