This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes nullpointer exception while trying to connect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "nullpointer exception while trying to connect" Watch "nullpointer exception while trying to connect" New topic
Author

nullpointer exception while trying to connect

siva krishnan
Greenhorn

Joined: Apr 26, 2003
Posts: 21
Friends,

I am getting a strange problem.
I am trying to connect to a local Access DB through sun.jdbc.odbc.JdbcOdbcDriver.

The program works fine when I run it as a standalone program.
But the same piece of code gives a

java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:435)

when I run in the Websphere environment.

Are there any particular JARs that I need to replace in WSAD which might fix the problem. I did try replacing the rt.jar file in a couple of places in WSAD but I am still getting the nullpointer exception.

code snippet :

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:testDB","test", "test");
<<Exception is thrown at the above statement>>

Any suggestions ?


Cheers<br />Siva<br />SCJP 1.4<br />SCWCD 1.3
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The default JVM for Websphere is provided by IBM, not Sun, and I'm not sure if it includes Suns's extra classes. This may be the problem you're running into.

Try installing the Sun JVM and configuring WAS to use this instead.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Siva,
IBM doesn't support WSAD or WebSphere App Server if you change the JVM. I strongly discourage you from doing that or trying to replace the rt.jar files. It may create other problems down the road. Instead add the Sun classes to your classpath.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

A better solution of course would be to stop stop using Access and the JDBC-ODBC bridge. If you don't have DB2 there are a number of free databases which provide Type 2, 3 and 4 drivers.

(Now that I think back, we changed the JVM running applications inside WSAD and not the JVM for WSAD itself. This was caused by an incompatibility between the IBM and SUN RMI implementations - the two can't talk to each other )
siva krishnan
Greenhorn

Joined: Apr 26, 2003
Posts: 21
(Now that I think back, we changed the JVM running applications inside WSAD and not the JVM for WSAD itself. )


Could you please elaborate on this ?
How do we change the JVM running applications inside WSAD ?

Due to limitations, we have to use the Access DB for this application.

Thank you for your advice.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Siva,
When you run an application (with a main method) in WSAD, it picks the JVM based on the one you specified in the project properties. Each project can use a different JVM and none of them have to be the same as the one WSAD itself is running under. (WSAD/Eclipse is java based and therefore needs a JVM.)

If you are running a server app (web project, ejb project), the situation is more complex. To the best of my knowledge, you can't switch that JVM as WSAD is tied to the server.
siva krishnan
Greenhorn

Joined: Apr 26, 2003
Posts: 21
Thanks Jeanne....I will try the approach you suggest.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nullpointer exception while trying to connect