java - Null pointer exception on other machines other than Mine -


this question has answer here:

i'm writing java swing app in eclipse. i've exported runnable jar. , when run it. working fine. i've sent same jar second machine. , when ran it, surprise, therw null pointer exception.

below piece of code.

try {        string dburl = path.getdburl();         system.out.println(dburl);         textarea.append(dburl + "\n");        system.out.println(path.getsystemid + " s id \n");        textarea.append(path.getsystemid + "\n");         // connect excel        class.forname("sun.jdbc.odbc.jdbcodbcdriver").newinstance();        connection myconn = drivermanager.getconnection(dburl);        string querystring = "select sum(pages) totalunitscount,sum(totalerrors) totalerror, sum(iif(type 'formatting error ',(totalerrors),0)) formsattingcount, sum(iif([type] 'x ref error ',(totalerrors),0)) [x ref counterrs]," + "sum(iif(((type 'formatting error ' , critical<>0)),(critical),0)) formsattingerrorcritical," + "sum(iif(((type 'x ref error ' , critical<>0)),(critical),0)) xreferrorcritical," + "count(iif(((type 'formatting error ' , noncritical<>0)),1,null)) formsattingerrornoncritical," + "count(iif(((type 'x ref error ' , noncritical<>0)),1,null)) xreferrornoncritical" + "  [quality sheet$]";         statement = myconn.preparestatement(querystring);        resultset = statement.executequery();        resultsetmetadata rsmetadata = resultset.getmetadata();        system.out.println(rsmetadata.getcolumncount());    } 

this working fine on machine, in second machine throwing exception in below line.

    connection myconn = drivermanager.getconnection(dburl); 

here settheexcelpath file

public class settheexcelsrcpath {     string getsystemid = system.getproperty("user.name");      public string getdburl() {         return "jdbc:odbc:driver={microsoft excel driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};dbq=c:\\users\\" + getsystemid                 + "\\desktop\\quality sheets\\quality_template.xlsx;";     }  } 

please let me know going wrong , how can fix this.

here i'm not getting exception on machine, getting thrown on machine, have debugged if issue on machine.

here stack trace

 java.lang.nullpointerexception @  sun.jdbc.odbc.jdbcodbcdriver.initialize(jdbcodbcdriver.java: 453) @  sun.jdbc.odbc.jdbcodbcdriver.connect(jdbcodbcdriver.java: 153) @  java.sql.drivermanager.getconnection(unknown source) @  java.sql.drivermanager.getconnection(unknown source) @  src.files.testexcel. < init > (testexcel.java: 39) @  src.files.reportsgeneratorgui$3.actionperformed(reportsgeneratorgui.java: 91)  @ javax.swing.abstractbutton.fireactionperformed(unknown source) @  javax.swing.abstractbutton$handler.actionperformed(unknown source) @  javax.swing.defaultbuttonmodel.fireactionperformed(unknown source) @  javax.swing.defaultbuttonmodel.setpressed(unknown source) @  javax.swing.plaf.basic.basicbuttonlistener.mousereleased(unknown source) @ java.awt.component.processmouseevent(unknown source) @  javax.swing.jcomponent.processmouseevent(unknown source) @  java.awt.component.processevent(unknown source) @  java.awt.container.processevent(unknown source) @  java.awt.component.dispatcheventimpl(unknown source) @  java.awt.container.dispatcheventimpl(unknown source) @  java.awt.component.dispatchevent(unknown source) @  java.awt.lightweightdispatcher.retargetmouseevent(unknown source) @  java.awt.lightweightdispatcher.processmouseevent(unknown source) @  java.awt.lightweightdispatcher.dispatchevent(unknown source) @  java.awt.container.dispatcheventimpl(unknown source) @  java.awt.window.dispatcheventimpl(unknown source) @  java.awt.component.dispatchevent(unknown source) @  java.awt.eventqueue.dispatcheventimpl(unknown source) @  java.awt.eventqueue.access$500(unknown source) @  java.awt.eventqueue$3.run(unknown source) @  java.awt.eventqueue$3.run(unknown source) @  java.security.accesscontroller.doprivileged(native method) @  java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(unknown source) @  java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(unknown source) @ java.awt.eventqueue$4.run(unknown source) @  java.awt.eventqueue$4.run(unknown source) @  java.security.accesscontroller.doprivileged(native method) @  java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @  java.awt.eventdispatchthread.pumponeeventforfilters(unknown source)  @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source)  @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source)  @ java.awt.eventdispatchthread.pumpevents(unknown source) @  java.awt.eventdispatchthread.run(unknown source) 

for debugging i've added below code in file.

try {     try {         class.forname("sun.jdbc.odbc.jdbcodbcdriver").newinstance();     } catch (instantiationexception | illegalaccessexception e) {         // todo auto-generated catch block         e.printstacktrace();     } } catch (classnotfoundexception e) {     textarea.append("where oracle jdbc driver?\n");     e.printstacktrace();     return; } textarea.append("jdbc odbc driver registered!\n");  connection myconn; try {     myconn = drivermanager.getconnection(dburl, "", ""); } catch (sqlexception e) {     textarea.append("connection failed! check output console\n");     e.printstacktrace();     return; }  if (myconn != null) {     textarea.append("you made it, take control database now!\n"); } else {     textarea.append("failed make connection!\n"); } 

when run in machine,

jdbc odbc driver registered! made it, take control database now!

when same on second machine, gives

jdbc odbc driver registered!

but not returning connection status. going wrong?

thanks

he can find driver class, otherwise throw classnotfoundexception. tries initialize jdbcodbcdriver , throws nullpointerexception in line 453 in initialize(). suppose configuration issue. maybe uses configuration files jdbc initialization other think does.

unfortunately don't have sun.jdbc.odbc.jdbcodbcdriver class on machine, otherwise line 453.

hint: place lots of logging lines code, switch on logging on other machine , watch, parameters tries initialize jdbc.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -