Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MS Access Driver

 
Faisal Farooqui
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
prashant komaragiri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic