sign in to MS Access from java


I tried to connect my java program to Access DB using jdbc-odbc bridge when I write my connection code this Exception is thrown and I could not solve the problem

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(
    at sun.jdbc.odbc.JdbcOdbc.standardError(
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(
    at java.sql.DriverManager.getConnection(
    at java.sql.DriverManager.getConnection(
    at jdbc.TestAccesDBCon.getConnection(
    at jdbc.TestAccesDBCon.main(

This is my code :

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement();
    st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM users");
    ResultSetMetaData rsMetaData = rs.getMetaData();
    int numberOfColumns = rsMetaData.getColumnCount();
    System.out.println("resultSet MetaData column Count=" + numberOfColumns);

  private static Connection getConnection() throws Exception {
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String connectionString = "jdbc:odbc:Driver= " +
"{Microsoft Access Driver (*.accdb)};DBQ=TestDB.accdb;DriverID=01";
    return DriverManager.getConnection(connectionString);

why this exception is thrown? please help?

Seems that you don't have installed the ODBC Access Driver (ODBC drivers are optional when Access is installed !), try to install drivers from Access installation media, if you are on a 64 bit system you should install the 64 bit version of the driver.

If you, going in ODBC Manager GUI in Amministrative Tools under the control panel, won't find under the sources tab the source :

Microsoft Access Driver (*.accdb)

this means that the driver are not installed on your system and you need to install it.

You can download Access 2010 driver from here .