• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Access DB Connect Issues

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code:

public Connection getConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "c:/IssuanceTracker/IssuanceTracker.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";database+= filename.trim();
System.out.println(database);
Connection con = DriverManager.getConnection( database ,"","");
return con;
}
catch (Exception e) {
System.out.println("Error: " + e);
e.printStackTrace();
return null;
}
}

Yields the following error:

java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:538)
at java.sql.DriverManager.getConnection(DriverManager.java:188)
at issuancetracker.DataAccess.getConnection(DataAccess.java:27)
at issuancetracker.testmain.main(testmain.java:21)

I've included the rt.jar file in my project. I'm using WSAD 5.1.2. Can anyone please help. Thanks, Bill
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";database+= filename.trim();



try this


String url ="jdbc:odbc:DRIVER={Microsoft Access Driver
(*.mdb)};DBQ= c:\\IssuanceTracker\\IssuanceTracker.mdb";


[ August 31, 2006: Message edited by: Saif Uddin ]
 
Bill Warner
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies! I get the same errors with the suggested changes.

I could really use some help. I'm new to Java and this problem doesn't seem to make sense. Co-workers can execute the same code successfully w/o error. Any help would be appreciated.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of accessing the MDB file directly, have you tried setting up an ODBC data source? Some info about that can be found here.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic