This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
GCJ and MySQL Connector for Java
- From: Spyros Stathopoulos <foucault dot online at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 20 Nov 2005 17:10:56 +0200
- Subject: GCJ and MySQL Connector for Java
Hi everyone,
I've created a little program to connect to my local MySQL database
and then exit, just for test. Here it is:
package org.testing;
import java.sql.*;
public class TestConnectMySQL {
public static void main(String[] args) {
System.out.print("Creating the Database URL...");
String dbURL = "jdbc:mysql://localhost/MyDat";
System.out.println("Done!");
try{
Class.forName("com.mysql.jdbc.Driver"); // or
Class.forName("org.gjt.mm.mysql.Driver") yields the same result
DriverManager.setLogStream(System.err);
System.out.print("Connecting, please wait...");
Connection conn = DriverManager.getConnection(dbURL);
System.out.println("Done!");
System.out.println("OK successfully connected,\n" +
"will close now!");
conn.close();
System.out.println("Terminated successfully");
}
catch(ClassNotFoundException e){System.out.println("Cannot
load driver:\n " + e);}
catch(SQLException e){System.out.println("Failed Access :-(" + e);}
catch(Exception e){}
}
}
I compile it succesfully with gcj as following
gcj -o MySQL-Test --main=org.testing.TestConnectMySQL -classpath
/usr/share/java/mysql-connector-java.jar:.
src/org/testing/TestConnectMySQ
L.java
However when I am trying to execute the output program I get the
following error:
Cannot load driver:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found in
gnu.gcj.runtime.SystemClassLoader{urls=[file:./,file:./],
parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
which is produced from my program.
Compiling into bytecode with Sun's compiler and then executing java
-classpath /usr/share/java/mysql-connector-java.jar TestConnectMySQL
establishes the connection and program executes properly.
Any ideas? Is it a GCJ issue?
Thank you all in andance,
Spyros "Foucault" Stathopoulos