Thursday, 30 January 2014

Create MS Access File

How to create MS-Access file using JAVA :-


Hey Guys !!! Welcome again to my blog. Today I came to you with the Java Code for creating the MS Access file of any version (upto 2010). Using this code you can create an MS Access file at any path where you want to create.

For the below code working properly, you need to download some jar files whose links are given below :-
1. jackcess-2.0.2.jar
2. commons-lang-2.0.jar
3.commons-logging-1.1.3.jar

Now set the classpath of the jar files you have downloaded from the link given above.

After setting the classpath, the only work we have to do is to code. So here we go.......

JackcessLibrary.java :-

 import com.healthmarketscience.jackcess.*;  
 import java.io.File;  
 public class JackcessLibrary {  
   public static void main(String[] args) {  
     try {  
       DatabaseBuilder.create(Database.FileFormat.V2007, new File("D:/AccessDatabase.accdb"));  
     } catch (Exception e) {  
       System.out.println(e);  
     }  
     System.out.println("Done!");  
   }  
 }  

In the above code I created a MS-Access file for MS Office 2007. Now you can compile and run the above code to create a MS-Access file in the D: drive and the name of the file will be "AccessDatabase.accdb".

I hope you will find this post helpful in various JAVA Projects. If you face any difficulty in this post you can ask it by commenting here. i will reply as soon as possible.

For more java codes................ stay connected  :-)