Improve company productivity with a Business Account.Sign Up

x
  • 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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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