Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

jdbc to odbc on linux with unixODBC

143 views
Skip to first unread message

Lewis Smith

unread,
Nov 28, 2002, 11:42:57 AM11/28/02
to
I am looking for some help with a problem I have been working on for a
few days now. I would be eternally greatful for any help you guys can
point my way

I need to set up on a Linux box an ODBC connection to mySQL.

To this end I have installed unixODBC and myODBC, and the tests work
fine. However, when I run a simple java proggy to this connection I get
the following error:

java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:435)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at SelectFromPer.main(SelectFromPer.java:40)

This immplies to me that the dirver is loading ok...?

here's my code:

import java.sql.*;

class SelectFromPer {
public static void main(String argv[]) {
try {
// Load the JDBC-ODBC bridge
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

// specify the ODBC data source's URL
String url = "jdbc:odbc:myIMDB";

// connect
Connection con = DriverManager.getConnection(url,"UserIM","UserIM");

// create and execute a SELECT
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery
("SELECT MSname,MCname,Minitials FROM Member");

System.out.println("Class is SelectFromPer\n");
// traverse through results
System.out.println("Found row:");

while (rs.next()) {

// get current row values
String Surname = rs.getString(1);
String FirstName = rs.getString(2);
int Category = rs.getInt(3);

// print values
System.out.print (" Surname=" + Surname);
System.out.print (" FirstName=" + FirstName);
System.out.print (" Category=" + Category);
System.out.print(" \n");
}

// close statement and connection
stmt.close();
con.close();
} catch (java.lang.Exception ex) {

ex.printStackTrace();
}
}
}

thanks in advance for any help

lewis

Joseph Weinstein

unread,
Nov 28, 2002, 2:43:24 PM11/28/02
to Lewis Smith

Lewis Smith wrote:

> I am looking for some help with a problem I have been working on for a
> few days now. I would be eternally greatful for any help you guys can
> point my way
>
> I need to set up on a Linux box an ODBC connection to mySQL.
>
> To this end I have installed unixODBC and myODBC, and the tests work
> fine. However, when I run a simple java proggy to this connection I get
> the following error:
>
> java.lang.NullPointerException
> at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:435)
> at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
> at java.sql.DriverManager.getConnection(DriverManager.java:512)
> at java.sql.DriverManager.getConnection(DriverManager.java:171)
> at SelectFromPer.main(SelectFromPer.java:40)
>
> This immplies to me that the dirver is loading ok...?

yes, the driver loaded OK, because the JdbcOdbcDriver class is in the stacktrace.
It is an example of a basic programming error that the driver would suffer a
null-pointer exception in response to a simple standard getConnection() call.
If you can find a real jdbc driver, it'll make your life easier. Check the documentation
for that driver. I suspect the exception comes from string processing of the URL,
where it expects more in the URL than there is...

Joe Weinstein at BEA

Lewis Smith

unread,
Nov 29, 2002, 4:31:53 AM11/29/02
to
Joseph,
Thanks for your reply, it is greatly appreciated.

I am using the standard Sun drivers that came with SDK 1.4_1

Can you recommend other JDBC ODBC drivers?

Thanks,

Lewis

Joseph Weinstein

unread,
Nov 29, 2002, 1:15:56 PM11/29/02
to Lewis Smith

Lewis Smith wrote:

> Joseph,
> Thanks for your reply, it is greatly appreciated.
> I am using the standard Sun drivers that came with SDK 1.4_1

yep. don't.

> Can you recommend other JDBC ODBC drivers?

I can't. The real path is to find a straight jdbc driver for the DBMS.
Joe

Mark Matthews

unread,
Nov 29, 2002, 2:02:07 PM11/29/02
to Joseph Weinstein, Lewis Smith
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joseph Weinstein wrote:
>
> Lewis Smith wrote:
>
>
>>Joseph,
>>Thanks for your reply, it is greatly appreciated.
>>I am using the standard Sun drivers that came with SDK 1.4_1
>
>
> yep. don't.
>
>
>>Can you recommend other JDBC ODBC drivers?
>
>
> I can't. The real path is to find a straight jdbc driver for the DBMS.
> Joe
>

I answered this in the myo...@lists.mysql.com mailing list, but it
appears that Lewis might have missed it. He should try using MySQL
Connector/J which is the JDBC driver for MySQL:

http://www.mysql.com/products/connector-j/

-Mark


- --
For technical support contracts, visit https://order.mysql.com/?ref=mmma

__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mark Matthews <ma...@mysql.com>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer - JDBC/Java
/_/ /_/\_, /___/\___\_\___/ Flossmoor (Chicago), IL USA
<___/ www.mysql.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.1.90 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE957mytvXNTca6JD8RAqK9AKCPVSBVA7yZFeXIP6ot5w2XalfxSwCglCma
kVEbiwrK7WWgYe7HpOwlZ8w=
=5yt7
-----END PGP SIGNATURE-----

Lewis Smith

unread,
Dec 5, 2002, 8:09:02 AM12/5/02
to
cheers for all your help guys!

i was hoping not to have to use connector-j, and was having trouble
getting it to work anyway.

this is the path i have now taken and i am happily walking it. thanks again

lewis :-)

0 new messages