Click here to Skip to main content
15,867,750 members
Please Sign up or sign in to vote.
1.00/5 (9 votes)
See more:
How to add a new row in the MS Access back end through JAVA.
I'm using an Eclipse tool.
Posted
Updated 5-Dec-12 8:09am
v3
Comments
OriginalGriff 24-Nov-12 7:34am    
Perhaps, you should consider the advantages of being a little more polite.
You do not pay our wages.
You do not get charged for our services.
So you do not have the right to give orders and act like a petulant little schoolboy.

Perhaps, if you edit your question, change it to explain your problem and ask in a polite way instead, you might get a better response.
Just a thought.
You can use the "Improve question" widget to edit your question.
Akinmade Bond 5-Dec-12 14:06pm    
:thumbsup:
Abhishek Pant 24-Nov-12 11:57am    
my 5 to OriginalGriff; check this is it helps you Inserting Data Rows to MS Access Database[^]

1 solution

Java MS Access database connectivity

Follow these steps:

1)Go to the start->Control Panel->Administrative Tools-> data sources.

2)Click Add button and select the driver Microsoft Access Driver(*.mdb).

3)After selecting the driver, click finish button.

4)Then give Data Source Name and click ok button.

5)Your DSN will get created.

6) Restart your compiler and compile your java code.

For Inserting Data:
Java
import java.sql.*;
class AccessDatabase{
    public static void main(String[] args){
        try{
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
           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);
        }
    }
}

For deleting data:
Java
import java.sql.*;
class AccessDatabase{
    public static void main(String[] args){
        try{
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
           Statement st=con.createStatement();
           String name="roseindia";
           String address="delhi";
           int i=st.executeUpdate("delete from user where id=4");
           System.out.println("Row is deleted");
           }
        catch(Exception e){
            System.out.println(e);
        }
    }
}
 
Share this answer
 
Comments
Sachin Shinde11088 24-Nov-12 23:08pm    
Thanks for helping me yaar..
Tamer Hatoum 26-Nov-12 1:23am    
your welcome ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900