Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDBC Microsoft Access direct LINK

843854Jun 18 2004 — edited Jul 8 2004
Hi, I am doing something REALLY basic, but i cannot get it to work. I would appreciate it if any one knows what the problem is:-

I have an Access Database at C:\Northwind.mdb

I have a java program which only tries to link to this database. I haven't tried to do anything with it yet. However despite all my efforts i always get a nullPointerException when i try to link to it. (I am linking directly not via DSN)

Here is my code (there error message starts with the line with getConnection on it :-

####
import java.sql.*;

public class JDBCSample {

public static void main(java.lang.String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e) {
System.out.println("Unable to load Driver Class");
return;
}

try {
String filename = "C:/Northwind.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+=filename.trim()+";DriverID=22;READONLY=true";

System.out.println(database);

Connection con = DriverManager.getConnection(database,"", "");
}
catch (SQLException se) {
// Inform user of any SQL errors
System.out.println("SQL Exception: " + se.getMessage( ));
se.printStackTrace(System.out);
}
catch (Exception e) {
System.out.println("Error: "+e);
e.printStackTrace(System.out);
}
}
}
####

I get :-

Error: java.lang.NullPointerException
java.lang.NullPointerException

and think it must be an error in the line
jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Northwind.mdb;DriverID=22;READONLY=true

does anyone know what is wrong?

Mark
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2004
Added on Jun 18 2004
11 comments
264 views