Q:

How do I edit MS Access database using Java (NetBeans)

I'm trying to edit an MS Access database using some Java code (running NetBeans 7.2.1). I set up the data source and linked it to my database ProjectDatabase using the ODBC tool and named the data source DB, then i run the following code: 
import java.sql.*;
public class NewMain {
public static void main(String[] args) {
    try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       Connection con = DriverManager.getConnection("jdbc:odbc:DB");
       Statement st=con.createStatement();
       String name="roseindia";
       String address="delhi";
       int i=st.executeUpdate("insert into user(name,address)      values('"+name+"','"+address+"')");
       System.out.println("Row is added");
       }
    catch(Exception e){
        System.out.println(e);
    }
}
} 

The code runs without and error and returns the "Row is added" message. The problem is that when I go back to view the database the changes have not taken effect. I have tried this with a code for deleting the data, also to no effect. Has anybody had this problem and knows how to solve it? 
I'm running Windows 7 64-bit, Microsoft Office 64-bit with all the 64-bit drivers and I have been unable to find any mention of this problem through web searches.
Thanks in advance for any help =)

A:

First of all you are not closing the connection, so that is one problem. Also change your code to:
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection con = DriverManager.getConnection("jdbc:odbc:DB");
   Statement st=con.createStatement();
   con.setAutoCommit(false); //Notice change here
   String name="roseindia";
   String address="delhi";
   int i=st.executeUpdate("insert into user(name,address)      values('"+name+"','"+address+"')");
   con.commit(); //Notice change here
   System.out.println("Row is added");
   con.close(); //Notice change here

This will commit the changes to access database, so now you should be able to see data in MS Access.
Read here to know more about best practices for Closing and Releasing JDBC resources

