aspose file tools*
The moose likes JDBC and the fly likes MS Access Driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MS Access Driver" Watch "MS Access Driver" New topic
Author

MS Access Driver

Faisal Farooqui
Greenhorn

Joined: Jun 25, 2001
Posts: 13
hi
I'm new in JDBC can any 1 tell me how can i access data of ms access. pls write with sample code. my data base name is accounts. Thnx
===
FAF


====<BR>FAF
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The easiest way is to set up your access db with an ODBC (microsoft stuff) service. Then you can use the JDBC-ODBC bridge to get java to talk to ODBC.
You should be able to set this up in the OCBD section of the control panel, then use the sun.jdbc.odbc.JdbcOdbcDriver with the url "jdbc: odbc:accounts"
I have some sample code but I can't get to it at the moment :}
Apart from the ODBC stuff it's all the same anyways.
Dave.
[This message has been edited by David O'Meara (edited July 22, 2001).]
prashant komaragiri
Ranch Hand

Joined: Jan 23, 2001
Posts: 36
hi,
u can try something likethis.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:accounts") ;
/* assume that accounts is ur dsn */
Statement stmt = con.createStatement();
then u can get resultset object with this statement object
hope this helps
prashant

Sun Certified Programmer for Java 2 Platform
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
Be aware that the jdbc.odbc bridge has some significant restrictions, it is a type 1 driver which means you can only ever go forward through a result set, it does not understand the Access memo data type and it has problems with threading.
Link to some typical code
http://developer.java.sun.com/developer/techDocs/SearchData/qa/JDBC-ODBC_Bridge.html


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
prashant komaragiri
Ranch Hand

Joined: Jan 23, 2001
Posts: 36
hi,
u can try something likethis.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:accounts") ;
/* assume that accounts is ur dsn */
Statement stmt = con.createStatement();
then u can get resultset object with this statement object
hope this helps
prashant
Faisal Farooqui
Greenhorn

Joined: Jun 25, 2001
Posts: 13
sun.jdbc.odbc.JdbcOdbcDriver
is it included in JDK 1.3/ 1.4 (beta)? I got an error "class file not found". Would have i to download drivers for JDBC if so where can i find these drivers.
thanks every 1 for reply
===
FAF
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Faisal, the sun.jdbc.odbc.JdbcOdbcDriver is included with the JDK. You will need to set up your DSN though so that your program can access your DB. You will need to do this through the ODBC settings in control panel. There is a JDBC tutorial at Sun's site that can help you with this.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MS Access Driver