Link to home
Start Free TrialLog in
Avatar of PearlJamFanatic
PearlJamFanatic

asked on

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.
Avatar of PearlJamFanatic
PearlJamFanatic

ASKER

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.
You need to specify data source in ODBC
Avatar of Mick Barry
you not creating a Statement

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");
---------------------------------
for_yan: how do i do that?
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perhaps rgagnon eamples should also work, but I didn't try it taht way - I used ODBC, and it worked for me