Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:56:24+00:00 2026-05-30T17:56:24+00:00

Currently I have one application in which I am able to access .mdb or

  • 0

Currently I have one application in which I am able to access .mdb or .accdb
file with JdbcOdbcDriver to append some data.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con = DriverManager.getConnection("jdbc:odbc:MsAccessDSN");

but in this, I need to configure System DSN. We need to add new Data Source (Microsoft Access Driver) and then need to provide location of .mdb file. Only then above code will work.

Suppose I want to run my application on other system then I need to do same thing to that computer.
If I give my application to the client and he/she don’t know how to configure .mdb file. Then my whole effort will waste.
So any driver is available by which I create .mdb file by my Java Code and then append all the data into the table of .mdb file.
Or is there any other way, where Java code can create .mdb file and able to access this database file.

I tried this code which append data without configuring System DNS:

public class TestMsAccess {

private static Connection con;
private static Statement stm;
private static String tableName = "EmpDetail";
private static int id_is = 2;
private static String name_is = "Employee1";

public static void main(String[] args) throws ClassNotFoundException, SQLException {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\MSAccessProject/Employee.mdb", "", "");

    stm = con.createStatement();
    // enter value into table
     String addRow = "INSERT INTO " + tableName  + " VALUES ( "
        + id_is + ", '" 
        + name_is + "')";
     stm.execute(addRow);

     if (con != null) { con.close(); }
     if (stm != null) { stm.close(); }
}

}

But the problem is, this code not create .mdb file automatically but work when I create .mbd file and table before running this code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:56:25+00:00Added an answer on May 30, 2026 at 5:56 pm

    Update for Jackcess 2.x: Databases are now created (or opened) using DatabaseBuilder, so to create a new database file we do

    import java.io.File;
    import java.io.IOException;
    
    import com.healthmarketscience.jackcess.Database;
    import com.healthmarketscience.jackcess.Database.FileFormat;
    import com.healthmarketscience.jackcess.DatabaseBuilder;
    
    public class JackcessDemoMain {
    
        public static void main(String[] args) {
            String dbPath = "C:/Users/Public/newDb.accdb";
            // using try-with-resources is recommended to ensure that 
            //   the Database object will be closed properly
            try (Database db = DatabaseBuilder.create(FileFormat.V2010, new File(dbPath))) {
                System.out.println("The database file has been created.");
            } catch (IOException ioe) {
                ioe.printStackTrace(System.err);
            }
    
        }
    
    }
    

    Original answer for Jackcess 1.x (deprecated):

    If you would like to create the “.mdb” file through java, you can use the Jackcess Java library which is one of the pure Java Library for reading from and writing to MS Access databases. Currently supporting versions include 2000-2007 I guess. Please have a look at the below example for better understanding:

    1. Download Jackcess Java library (jackcess-1.2.6.jar)
      from http://jackcess.sourceforge.net/
      and commons-logging-1.1.jar
      from http://commons.apache.org/logging/download_logging.cgi
      and commons-lang-2.0.jar
      from http://www.findjar.com/index.x?query=commons-lang
    2. Add both jars to your classpath.
    3. Try the below code to create a database automatically:

    package com.jackcess.lib;
    
    
    import com.healthmarketscience.jackcess.ColumnBuilder;
    import com.healthmarketscience.jackcess.Database;
    import com.healthmarketscience.jackcess.Table;
    import com.healthmarketscience.jackcess.TableBuilder;
    import java.io.File;
    import java.io.IOException;
    import java.sql.SQLException;
    import java.sql.Types;
    
    /**
     *
     * @author sarath_ivan
     */
    public class JackcessLibrary {
    
        private static Database createDatabase(String databaseName) throws IOException {
            return Database.create(new File(databaseName));
        }
    
        private static TableBuilder createTable(String tableName) {
            return new TableBuilder(tableName);
        }
    
        public static void addColumn(Database database, TableBuilder tableName, String columnName, Types sqlType) throws SQLException, IOException {
            tableName.addColumn(new ColumnBuilder(columnName).setSQLType(Types.INTEGER).toColumn()).toTable(database);
        }
    
        public static void startDatabaseProcess() throws IOException, SQLException {
            String databaseName = "C:/Users/compaq/Desktop/employeedb.mdb"; // Creating an MS Access database
            Database database = createDatabase(databaseName);
    
            String tableName = "Employee"; // Creating table
            Table table = createTable(tableName)
                    .addColumn(new ColumnBuilder("Emp_Id").setSQLType(Types.INTEGER).toColumn())
                    .addColumn(new ColumnBuilder("Emp_Name").setSQLType(Types.VARCHAR).toColumn())
                    .addColumn(new ColumnBuilder("Emp_Employer").setSQLType(Types.VARCHAR).toColumn())
                    .toTable(database);
    
            table.addRow(122875, "Sarath Kumar Sivan","Infosys Limited.");//Inserting values into the table
        }
    
        public static void main(String[] args) throws IOException, SQLException {
            JackcessLibrary.startDatabaseProcess();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a web application that have about 6-12 pages. On each one
I currently have a user's table which contains a one-to-one relationship for Youtube OAuth
I currently have 2 concrete methods in 2 abstract classes. One class contains the
I am currently writing an application in VS2010 which will access many different SQL
I'm currently in the development process of an application which needs to be able
I'm working on an application which walks through every file in some directories and
Currently I have developed one application on android 2.3 platform. But when i test
I have an EJB3 application which consists of some EJB's for accessing a DB,
I currently have a gridview that has an asp:ButtonField as one of the columns.
I (currently) have two forms, one that needs to call the other. In other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.