• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting to MS Access

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am trying to do a tiny practice on connecting to a simple Access Database stored locally. Some web sites explained using DriverManager, but I am confused on the construction on the url part. Anyone can explain to me how DriverManager is used and how can I know what the url is supposed to be? Any methods to connection to Database other than DriverManager are welcomed.

Thanks in advance
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I'm not sure if i can resolve your problem but i can tell how i connect to access in my java application.

I have a java class called connector which connects to access like following:

public class connectionAccess {

Connection con = null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement pstmt = null;

static{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
System.out.println("Error cnfe: "+ ex.getMessage());
}
}

public void createDataBaseConnection() throws SQLException{

con = DriverManager.getConnection("jdbc:odbc:DBNameSpecifiedInControlPanel","","");
stmt = con.createStatement();
}

public void closeDataBaseConnection() {

try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (con != null) con.close();
} catch (SQLException ex) {
}
}
}


then you can call the method createDataBaseConnection before you do your selects/updates/deletes and then the closeDataBaseConnection method.

In the control panel / odbc administrator you have to make System DSN to your access DB called DBNameSpecifiedInControlPanel
 
Felix Li
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have got it, thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic