Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to connect to MS Access DB thru servlet?

Status
Not open for further replies.

Vandys

IS-IT--Management
Aug 3, 2000
29
AU
Hi all,

I have an MS Access Database. I want to connect to it thru' Servlet. I looked at the FAQ and found a link to this problem. But that is not getting me the result. Can anyone pls. put down some code lines to do this?? I have created a dsn with the name "prix". PLEASE.......
 
It makes no difference whether you are using Servlets are plain vanilla Java, the Database Connection Code is the same. Here is some code that I posted a while back for someone with the same question.
Code:
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String dsn = "prix";
String url = "jdbc:odbc:" + dsn;

Connection conn = null;
try {
   Class.forName(driver);
   conn = DriverManager.getConnection(url);
   /* Do your stuff */
}
catch (SQLException sqle) {
   /* SQL Error.  Do your error handling */
}
catch (ClassNotFoundException cnfe) {
   /* Driver not found.  Do your error handling */
}
finally {
   /* Make sure you close the Connection */
   if (conn != null) {
      try {conn.close();}
      catch(Exception e) {}
   }
}
Hope this helps. Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top