I am having problems getting the MySQL Connector/J set up. I have followed instructions and cannot connect. Can anyone see what I have done wrong?
This is my code: ------------------------------------------------------- import java.sql.*;
class TestDBConnection {
public static void main(String[] arg) { // My host computer is dara, the database I want // is test String url = "jdbc:mysql://dara/test"; String driver = "com.mysql.jdbc.Driver";
String query = "SELECT * FROM Test WHERE number = 136";
try { //Load the jdbc-odbc driver Class.forName(driver); //.newInstance();
// Attempt a connection to a driver Connection con = DriverManager.getConnection(url, "user", "password");
// Create a statement object so we can submit SQL statements // the driver Statement stmt = con.createStatement();
// Submit a query ResultSet rs = stmt.executeQuery(query);
// Display all results from the result set printResultSet(rs);
-------------------------------------------------- Here is the Exception and the stack trace I get:
SQL Exception: Driver not found for URL: jdbc:mysql://dara/test java.sql.SQLException: Driver not found for URL: jdbc:mysql://dara/test at 0x4027e15f: java.lang.Throwable.Throwable(java.lang.String) (/usr/lib/libgcj.so.3) at 0x402710d2: java.lang.Exception.Exception(java.lang.String) (/usr/lib/libgcj.so.3) at 0x40313294: java.sql.SQLException.SQLException(java.lang.String, java.lang.String, int) (/usr/lib/libgcj.so.3) at 0x40313244: java.sql.SQLException.SQLException(java.lang.String) (/usr/lib/libgcj.so.3) at 0x40313102: java.sql.DriverManager.getConnection(java.lang.String, java.util.Properties) (/usr/lib/libgcj.so.3) at 0x4031303a: java.sql.DriverManager.getConnection(java.lang.String, java.lang.String, java.lang.String) (/usr/lib/libgcj.so.3) at 0x4039a347: ffi_call_SYSV (/usr/lib/libgcj.so.3) at 0x4039a307: ffi_raw_call (/usr/lib/libgcj.so.3) at 0x40245528: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3) at 0x40245e34: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.3) at 0x40243424: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/libgcj.so.3) at 0x4039a1bc: ?? (??:0) at 0x40258308: gnu.gcj.runtime.FirstThread.call_main() (/usr/lib/libgcj.so.3) at 0x402c30b1: gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.3) at 0x40264fdc: _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.3) at 0x4023178c: _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.3) at 0x08048900: ?? (??:0) at 0x420158d4: ?? (??:0) at 0x080486c1: ?? (??:0)
> Here is the Exception and the stack trace I get: > > SQL Exception: Driver not found for URL: > jdbc:mysql://dara/test > java.sql.SQLException: Driver not found for URL: > jdbc:mysql://dara/test > at 0x4027e15f:
bada bing! an error message with a useful message shocker! ;-)
your mysql driver is not set up properly. the driver file needs to live in the /lib directory of your JDK installation. that location's off the top of my head so you're better off checking the documentation that came with your driver for the exact location.
I put the driver jar file in $JAVA_HOME/jre/lib/ext, which is where the documentation says to put it and I have also tried to just put the driver jar in my classpath. Both give the same error.
> I put the driver jar file in $JAVA_HOME/jre/lib/ext, which > is where the documentation says to put it and I have also > tried to just put the driver jar in my classpath. Both > give the same error.
ah, try looking at the URL used to make the connection. you're using the typical ODBC format: