• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer error while running JDBC code on another machine

 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm writing a Java Swing app in Eclipse. I've exported as a runnable jar. And when I run it. Everything is working fine. So I've sent the same JAR to my second machine. And When I ran it, to my Surprise, this therw a null pointer Exception.

Below is a piece of my code.


This is working fine on my Machine, But in my second machine it is throwing the exception in the below line.


Please let me know where Am I going wrong and how Can I fix this.

Here I'm not getting Exception on my machine, it is getting thrown on another machine, I would have debugged if the issue was on my Machine.

Here is my stack trace

java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:453) at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at Src.Files.TestExcel.(TestExcel.java:39) at Src.Files.ReportsGeneratorGUI$3.actionPerformed(ReportsGeneratorGUI.java:91) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

Thanks
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate to state the obvious but its saying it cant find the file.  

I know this is probably not the answer you were looking for but I always used the JFilechooser to select a file so I knew I got the URL correct.
There are tons of examples on the net on how to use JFilechooser.

But if this is a config file.  I always used the getRecource



And there are examples for getRecource on the net as well.
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Bad, I just remembered your doing jdbc.odbc connection.  Its sounds like you have not setup the odbc part on the second machine.

http://www.dreamincode.net/forums/topic/207385-java-to-mysql-connection-using-the-jdbc-odbc-bridge/

 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another possibility is that maybe the driver is missing on the second machine
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this example.   Notice it defines DriverID.   Will do some research to see what that does

 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for debugging I've added the below code in the file.


When I run this in my machine, I get

JDBC ODBC Driver Registered!
You made it, take control your database now!


When I do the same on the second machine, it gives

JDBC ODBC Driver Registered!


But not returning the connection status. 
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
myConn will never be null.
It cannot.
If getConnection fails it will throw an exception.

I would check your logs.
 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:myConn will never be null.
It cannot.
If getConnection fails it will throw an exception.


Thanks for that quick point 

I would check your logs.


where can I find them in the target system? 
 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
I would check your logs.


Here is my log output

java.lang.NullPointerException
        at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:453)
        at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at Src.Files.TestExcel.TestMyExcel(TestExcel.java:51)
        at Src.Files.ReportsGeneratorGUI$3.actionPerformed(ReportsGeneratorGUI.j
ava:93)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(U
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is at this point that I say that the JDBC-ODBC bridge driver was never intended for real use.
It is buggy.
It has appalling error handling.
And so on...

It's why it was removed, as people kept falling into the trap of actually trying to use it (usually with Access).

Anyway, if you have to use it (and I doubt there's any decent free Excel ODBC ones out there) I suppose you're stuck with it.

My guess is that the file doesn't exist, or is not able to be opened, or is already open, or some ODBC magic is missing?
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any chance you are using a different JDK on your second machine?

According to this Oracle article about the status of the JDBC-ODBC Bridge, it will be removed in JDK8. So that might be a reason why it doesn't work on the first machine (running JDK7 or prior) and not on the other one (running JDK8).
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it seems the JdbcOdbcDriver is loaded (otherwise Class.forName would throw a ClassNotFoundException), you are probably running JDK7 (or prior) on both machines. Because I can't find the source for the JdbcOdbcDriver (it is not included in the sources for JDK7 nor JDK6), I decompiled the version of JDK7 and then I searched for the initialize() method. Although this method is pretty useless in its decompiled version, I noticed you can enable tracing to get more information about what's going on and what's going wrong.

This Oracle article about JDBC-ODBC Bridge Driver mentions clearly how you can enable tracing.
9.3.6     Debugging
The Bridge provides extensive tracing when DriverManager tracing is enabled. The following line of code enables tracing and sends it to standard out:

     java.sql.DriverManager.setLogStream(java.lang.System.out);


So I would add this line to the main method and see if this additional output shows what's wrong on your second machine

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic