• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

NullPointerException

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Errr what platform are you trying this from?
 
david haul
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is done on unix platform.
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic