INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Java Code to Start MS Access and Open Specific Database File

Java Code to Start MS Access and Open Specific Database File

Java Code to Start MS Access and Open Specific Database File

(OP)
I searched and didn't find this answered in the forum yet.
I am developing a Swing form in NetBeans. I need to add a button to my form and build an event that will open MS Access with a specified database file. I can add the button but I don't have a clue how to write the code for opening the MS Access application. Yes, I am new to Java.
Thanks for taking the time to respond.

RE: Java Code to Start MS Access and Open Specific Database File

Use JDBC to open the file using the fitting JDBC for Access driver, and use it through there.

RE: Java Code to Start MS Access and Open Specific Database File

(OP)
Thanks for the quick response.
I used your reply to search google for code and found something that looks like it might work. If it does work I will post it to this thread later for others to use.
While I am fairly accomplish VBA coder, Java has me completely baffled.

RE: Java Code to Start MS Access and Open Specific Database File

(OP)
Well I tried searching and again found nothing.
Do to my lack of experience with Java the solution offered by:

Quote (TomHu)

Use JDBC to open the file using the fitting JDBC for Access driver, and use it through there.

Might as well be written in greek. So if anyone has a solution that provides actual code I can copy and paste I would really appreciate it.

RE: Java Code to Start MS Access and Open Specific Database File

Do you want in Java
either
1. Process the data which are stored in MS Access table,
or
2. Call the external windows programm, i.e. MS Access ?

In 1. case use jdbc,
in 2.case try to look at something like this:
http://mrbool.com/run-external-windows-program-wit...

RE: Java Code to Start MS Access and Open Specific Database File

(OP)
Ok, finally got it working. The link provided by mikron got me started in the right direction. But the sample code at that link didn't get me to the final solution. I finally ended up doing a google search for examples of "Runtime.getRuntime().exec()" and that landed me here:
tutorialspoint

Wow, so glad I found that site. They provide exactly what I've been searching for the last few weeks. A Java language reference complete with code examples.

So for anyone else who finds this post searching for a similar solution, here is the code that ended up getting the job done for me.

CODE --> Java/NetBeans

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
try
{
    //create an array of two strings used to pass the program and file path to the exec process
    String[] cmdArray = new String[2];
    //assign the program path to the first item in the array
    cmdArray[0] = "C:\\Program Files\\Microsoft Office 15\\root\\office15\\MSACCESS.EXE";
    //assign the file path to the second item in the array
    cmdArray[1] = "C:\\Users\\UserName\\Documents\\MyDatabase.accdb";
    //call the exec process using the array as the arguments
    Runtime.getRuntime().exec(cmdArray,null);
}
    catch(Exception e)
{
    System.out.println(e.getMessage());
}
    } 

This code is assigned to a button on my Swing form and when the user presses the button an instance of MS Access is opened and the desired database file is loaded. The Swing form remains open in the background and the user can work in the Access platform until the task is completed.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close