Click here to Skip to main content
12,079,202 members (27,330 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Java Java SE J2EE
How to add a new row in the MS Access back end through JAVA.
I'm using an Eclipse tool.
Posted 24-Nov-12 1:29am
Edited 5-Dec-12 9: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.
GeekBond 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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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:
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:
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);
        }
    }
}
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100