Solved

Connect and retrieve data from MS access from java

Posted on 2011-03-15
9
410 Views
Last Modified: 2012-06-27
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
Comment
Question by:PearlJamFanatic
  • 5
  • 3
9 Comments
 

Author Comment

by:PearlJamFanatic
ID: 35136372
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
 
LVL 47

Expert Comment

by:for_yan
ID: 35136387
You need to specify data source in ODBC
0
 
LVL 92

Expert Comment

by:objects
ID: 35136396
you not creating a Statement
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 47

Expert Comment

by:for_yan
ID: 35136412

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
 

Author Comment

by:PearlJamFanatic
ID: 35136413
for_yan: how do i do that?
0
 

Author Comment

by:PearlJamFanatic
ID: 35136428
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 35136431
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
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 35136438
The datasource name should be the same as in Connection con1 = DriverManager.getConnection("jdbc:odbc:DataSourceName","user","passowrd");
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136446
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 90
stackato and cloud 4 85
ForLoop Example 3 48
fibonacci ten numbers 4 38
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question