| Author |
NullPointerException
|
david haul
Greenhorn
Joined: Sep 24, 2005
Posts: 2
|
|
I have attached my java file and added the comments for your understanding. The problem the program is successfully able to locate the driver details but unable to find the CSV file. My path details are as under: CSV File: /opt/Voip/classes/Report.csv Source Code: /opt/Voip/src/RemedyTickets.java Destination class file: /opt/Voip/classes/RemedyTickets.class ClassPath: This contains many other paths including, 1) /opt/gety/jdk1*/jre/bin/rt.jar //rt.jar is the file which contains the sun.jdbc.odbc.JdbcOdbcDriver 2) /opt/Voip/classes/ Other programs are working fine with this class path. I suppose the error message is because the program is expecting the file to be somewhere else rather than the current location. In the java connection string statement, I tried removing the entire path and gave only the file name but still getting the same error. con = DriverManager.getConnection("jdbc dbc river= {Microsoft Text Driver (*.txt;*.csv)};DBQ=Report.csv","","");//;DriverID=22;READONLY=false","",""); This is the error Message: Failed while establishing the connection with an Exception: java.lang.NullPointerException 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:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at RemedyTickets.<init>(RemedyTickets.java:15) at RemedyTickets.main(RemedyTickets.java:62) Can you help me out to solve this issue. Let me know if you have any issues. import java.io.*; import java.sql.*; import java.net.*; public class RemedyTickets { Connection con=null; Statement st=null; ResultSet rs=null; ResultSetMetaData rsmd=null; public RemedyTickets() { try { Class cls=Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String name = cls.getName().replace( '.' , '/' ) ; URL loc = cls.getResource( "/" + name + ".class" ) ; //System.out.println("Class Path: "+loc); // System.out.println(Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").getClass().getProtectionDomain()); //Working fine... } catch(Exception ex) { System.out.println("Failed while locating the driver: "+ex); ex.printStackTrace(); } try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Its working fine till here con = DriverManager.getConnection("jdbc dbc river= {Microsoft Text Driver (*.txt;*.csv)};DBQ=/opt/Voip/Classes/Report.csv","","");//;DriverID=22;READONLY=false","",""); System.out.println("Connection Established to the CSV File"); con=null; } catch(Exception e) { System.out.println("Failed while establishing the connection with an Exception: "+e); e.printStackTrace(); } } public static void main(String args[]) { RemedyTickets rt=new RemedyTickets(); } }
|
 |
Maximilian Xavier Stocker
Ranch Hand
Joined: Sep 20, 2005
Posts: 381
|
|
|
Errr what platform are you trying this from?
|
 |
david haul
Greenhorn
Joined: Sep 24, 2005
Posts: 2
|
|
|
this is done on unix platform.
|
 |
Maximilian Xavier Stocker
Ranch Hand
Joined: Sep 20, 2005
Posts: 381
|
|
Originally posted by david haul: this is done on unix platform.
That's the problem. ODBC is largely for Microsoft. There are some ODBC drivers for Linux/Unix http://www.google.ca/search?hl=en&q=Unix+ODBC&meta= So you will have to install them. In the end I am 99.9% sure you won't be using the Microsoft Text Driver you will end up using some UNIX ODBC text driver. The JdbcOdbcBridgeDriver is just a bridge from JDBC to ODBC it does not actually contain all the various ODBC drivers.
|
 |
 |
|
|
subject: NullPointerException
|
|
|