Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Posts
    3

    Unanswered: problems using gcj to compile mysql/jdbc code

    I'm new to the whole java and jdbc world, but I'm trying to use gcj to create binary executables of java code. Specifically, I'm trying to compile a test db query java code. When I use javac/java, it works just fine. Using gcj, the code will compile, but during execution, it crashes.

    Here is my code:

    ============================
    import java.sql.*;


    class MyDBTest
    {
    public static void main (String args[])
    {
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
    } catch(java.lang.InstantiationException e) {
    System.err.print("java.lang.InstantiationException ");
    System.err.println(e.getMessage());
    } catch(java.lang.IllegalAccessException e) {
    System.err.print("java.lang.IllegalAccessException ");
    System.err.println(e.getMessage());
    }

    try {
    String url = "jdbc:mysql://localhost/<db>";
    Connection con = DriverManager.getConnection(url, "<user>", "<pass>");

    Statement stmt = con.createStatement();
    String query = "SELECT * FROM VERTICALS";
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next()) {
    String s = rs.getString("vertical");
    float n = rs.getFloat("id");
    System.out.println(s + " " + n);
    }
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    }
    }
    }

    =============================
    I can create the .class file with:

    > javac -classpath mysql_jdbc.jar:. MyDBTest.java
    (where mysql_jdbc.jar is the mysql connector/j 3.1 jar)

    And run with:

    > java -cp mysql_jdbc.jar:. MyDBTest

    But when I try to compile with gcj:

    > gcj --main=MyDBTest -o DBTest --classpath=mysql_jdbc.jar:. MyDBTest.class
    (using the .class file created by javac above)

    I get the following errors when I execute:

    ClassNotFoundException: com.mysql.jdbc.Driver
    SQLException: Driver not found for URL: jdbc:mysql://localhost/<db>


    =================
    Any thoughts or ideas would be very much appreciated.

    Thanks,

    -Hani

  2. #2
    Join Date
    Oct 2004
    Posts
    4

    i have the seem pb!!

    hello

    Hani

    have you got the solution??

    Thank
    wazer

  3. #3
    Join Date
    Apr 2003
    Posts
    3

    No solution yet

    Just to follow up, I couldn't resolve the issue so I went a different route (can't recall at the moment).

    -Hani

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •