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
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
I am using the standard Sun drivers that came with SDK 1.4_1
Can you recommend other JDBC ODBC drivers?
Thanks,
Lewis
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
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-----
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 :-)