Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBO-ODBC NullPointerException

Status
Not open for further replies.

sjpatrick

Programmer
Sep 4, 2001
54
US
I continue to get a java.lang.NullPointerException error when trying to connect to an ODBC data source on my hetwork.

Code:
import java.sql.*;
 ... 
Connection j = getDataConnection();
 ... 
private static Connection getDataConnection() {
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc://theServer.com/theODBCname";
con = DriverManager.getConnection(url);
} catch (Exception e) {
 ... 
}
return con;
}

Obviously, the DriverManager if failing to get a Connection.

theODBCname data source on theServer.com requires no authentication.
Tried accessing theServer.com via its IP address.
Tried Class.forName with and without .newInstance()

This exact code with only the driver and database names changed works like a charm on a local mysql database.

In case it matters, theODBCname data source is a Foxpro flat file directory; this data source is used elsewhere on my network with no problem.

Forgive me, I am a Java n00b.
 
What line is throwing the NullPointerException ?
If the driver cannot connect, then there would be some other kind of exception I would have thought ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I don't know how to trace the error.

I am not even a good n00b.
 
Okay, turned off error trapping and got this:

Code:
jdbc:odbc://cltpsi01.cgraphics.com/PSI-Jdata
Exception in thread "main" java.lang.NullPointerException
        at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436)
        at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
        at java.sql.DriverManager.getConnection(DriverManager.java:525)
        at java.sql.DriverManager.getConnection(DriverManager.java:193)
        at HelloJava.getPsiJdataConnection(HelloJava.java:53)
        at HelloJava.main(HelloJava.java:12)

In my actual code, line 12 is the line:

Code:
Connection j = getDdataConnection();

Somewhat more useful I hope...
 
I get another vote for Java-Moron-of-the-Day.

ODBC data sources can only be accessed by the servers on which they live, not across a network.

Installed Java on the server in question and all works as advertised.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top