I'm trying to setup a mySQL connector and I'm not sure what's going wrong. Here is the error:
SQLException: No suitable driver found for jdbc:mysql://localhost/db?user=root&password=
Here is my java:
// ESTABLISH DRIVER INSTANCE
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
}
// ESTABLISH DB CONNECTION
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/db?" +
"user="+user+"&password="+pass);
// Do something with the Connection
//
//
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
Here is my build.xml:
<project>
<target name="run">
<javac srcdir="." destdir=".">
<classpath>
<pathelement path="./mysql-connector-java-5.1.38i/mysql-connector-java-5.1.38-bin.jar"/>
<pathelement location="./DB_Test.class"/>
</classpath>
</javac>
<java classname="DB_Test">
<classpath>
<pathelement path="./mysql-connector-java-5.1.38i/mysql-connector-java-5.1.38-bin.jar"/>
<pathelement location="."/>
</classpath>
</java>
</target>
</project>
I think the issue is likely to be in the build.xml because I am very inexperienced with ant. I'm not sure if both of those "pathelement path"s are necessary or if either one of them works. I'm wondering if I need to resort to eclipse just for this one jar.
I also think there could be an issue with my connection url syntax. Is "db" the name of the connection? Or the schema? Do I need a port number after my localhost?