• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Connect and retrieve data from MS access from java

String myDB =	"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/CRDUtil/data/CRD1.MDB";
con = DriverManager.getConnection(myDB,"","");
rs = stmt.executeQuery(sqlStr); //throws nullpointerexception

Open in new window


the last line throws exception.
0
PearlJamFanatic
Asked:
PearlJamFanatic
  • 5
  • 3
2 Solutions
 
PearlJamFanaticAuthor Commented:
do ineed to install something to get this working. I was connecting to oracle (using a different comnnection string) till now and it was working.
0
 
for_yanCommented:
You need to specify data source in ODBC
0
 
objectsCommented:
you not creating a Statement
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
for_yanCommented:

That's how I did connection to MS:

If you don't have user password just two empty lines should do like nothing between the quotes: "",""
-------------------------
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con1 = DriverManager.getConnection("jdbc:odbc:DataSourceName","user","passowrd");

Statement stmt1 = con1.createStatement();

ResultSet rs1 = stmt1.executeQuery("select Methods.MethodId, Methods.RunTime from Methods");
---------------------------------
0
 
PearlJamFanaticAuthor Commented:
for_yan: how do i do that?
0
 
PearlJamFanaticAuthor Commented:
0
 
for_yanCommented:
you go to control panel - administartive tools - ODBC - System DSN tab - add - Micosoft Access Driver(*mdb)  - specify dataosurce name and description (latter not important)  - then select and browse to the .mdb file
0
 
for_yanCommented:
The datasource name should be the same as in Connection con1 = DriverManager.getConnection("jdbc:odbc:DataSourceName","user","passowrd");
0
 
for_yanCommented:
Perhaps rgagnon eamples should also work, but I didn't try it taht way - I used ODBC, and it worked for me
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now