[unixODBC-support] JDBC to ODBC connection failing

Nicholas Campion campnic at gmail.com
Wed Feb 28 19:37:33 GMT 2007


I am writing an application using java that will need to connect to MySQL
through ODBC.  I have the connection between ODBC and MySQL working
correctly.  I can login and manipulate the database through isql.  However,
when i try and use JDBC to connect to unixODBC, I get repeated failures.

Exception in thread "main" java.lang.NullPointerException
    at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:471)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:188)
    at java.sql.DriverManager.getConnection(DriverManager.java:559)
    at java.sql.DriverManager.getConnection(DriverManager.java:211)
    at com.ibm.jdbc.test.TestDriver.main(TestDriver.java:23)
DriverManager.getConnection("jdbc:odbc:myodbc")
    trying driver[className=sun.jdbc.odbc.JdbcOdbcDriver,
sun.jdbc.odbc.JdbcOdbcDriver at 23a484ba]
*Driver.connect (jdbc:odbc:myodbc)
JDBC to ODBC Bridge: Checking security
No SecurityManager present, assuming trusted application/applet
JDBC to ODBC Bridge 2.0001
Current Date/Time: Wed Feb 28 10:43:04 CST 2007
Loading JdbcOdbc library
Unable to load JdbcOdbc library
java.sql.SQLException: Unable to load JdbcOdbc library
    at sun.jdbc.odbc.JdbcOdbc.<init>(JdbcOdbc.java:120)
    at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:464)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:188)
    at java.sql.DriverManager.getConnection(DriverManager.java:559)
    at java.sql.DriverManager.getConnection(DriverManager.java:211)
    at com.ibm.jdbc.test.TestDriver.main(TestDriver.java:23)

At first I thought it might not be finding JdbcOdbc.so so i modified our
java.library.path to include it:-
Djava.library.path=/usr/lib/jvm/java-1_4_2-ibm-1.4.2.s4/jre/bin/:/usr/lib/jvm/java-1_4_2-ibm-1.4.2.s4/jre/bin/classic:/usr/lib/xulrunner-1.8.0.1:/usr/lib:/usr/lib/unixODBC

This includes both the install location of the
jdbcodbc.so(/usr/lib/jvm/java-1_4_2-
ibm-1.4.2.s4/jre/bin/) and the unixODBC libraries.  I get a different error
when i remove these parameters, so I'm guessing that the code is finding the
necessary libraries.

Here is my code:
package com.ibm.jdbc.test;

import java.sql.*;

public class TestDriver {

    public static void main(String[] args) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
            java.sql.DriverManager.setLogStream(java.lang.System.out);
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        System.loadLibrary("odbc");
        System.loadLibrary("JdbcOdbc");



    try {
        Connection con;
        Connection con =
DriverManager.getConnection("jdbc:odbc:myodbc;UID=<MySQL
username>;PWD=<MySQL password>");
        } catch (SQLException e) {
            e.printStackTrace();
    }
    }

}

Where "myodbc" is the name of my DSN for my MySQL database, "MySQL username"
is my username for MySQL and "MySQL password" is my password for MySQL.  I
can access the myodbc DSN from isql using the credentials as I provide them
in the jdbc, but it seems like something else is causing the library to fail
loading.

All items are from the SUSE Linux Enterprise Server 10 install media.
Java : IBM Java 1.4.2 SR4 (I've recreated the problem using the sun jvm)
ODBC Mgr: unixODBC 2.2.11
ODBC driver unixODBC -> Mysql : MyODBC libmyodbc3-3.51.12.so
ODBC driver JDBC -> unixODBC : JDBC/ODBC bridge driver for javaq-1.4.2-ibm

I appreciate any information that might help me resolve my problem.

Thanks,
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20070228/df00d3de/attachment.html>


More information about the unixODBC-support mailing list