How To Insert A New Record to MS Access table database in GUI

Ads
 

How To Insert A New Record to MS Access table database in GUI

Hello, I've been working on the actionPerformed part of my java application that involves inserting a record into a 6-column table in my MS Access database table. I'm doing fine with retrieving the data with ResultSet, but I'm stuck on the actionPerformed events. The problem I'm having is that when the user clicks on the Add button, it's not doing anything (not even my JOptionPane). I'm stuck at this step. For simplicity, I am including only the add button listener and action events. I know I'm missing something, I just couldn't figure out where. Thanks in advance for your help. Below is part of my java code.

private class AddButtonListener implements ActionListener { public void actionPerformed (ActionEvent d) {

int donorNum = recordNum;

String name;
    name = firstNameTextField.getText();
String lastName;
    lastName = lastNameTextField.getText();
String middleI;
    middleI = mITextField.getText();
String charity;
    charity = comboBox.getSelectedItem().toString();

String pledge = pAmountTextField.getText();    
double pl;
     pl = Double.parseDouble(pledge);

record.setRecordNumber(donorNum);
record.setFirstName(name);
record.setLastName(lastName);
record.setMiddleInitial(middleI);
record.setCharity(charity);
record.setPledge(pl);

recNum.add(record.getRecordNumber());
lName.add(record.getLastName());
fName.add(record.getFirstName());
midI.add(record.getMiddleInitial());
lCharity.add(record.getCharity());
donAmount.add(record.getTotalPledge());

recordNum++;      


try {
    rs.moveToInsertRow();
    rs.updateInt(1, recordNum);
    rs.updateString(2, " " +name);
    rs.updateString(3, " " + lastName);
    rs.updateString(4, " " + middleI);
    rs.updateString(5, " " + pledge);
    rs.updateString(6, " " + charity);


    rs.insertRow();
    rs.moveToCurrentRow();
    st.close();
    rs.close();

    st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);        
    String sql = "select * from DonorTable";
    rs = st.executeQuery(sql);

    rs.next();

    firstNameTextField.setText(rs.getString("First_Name"));
    lastNameTextField.setText(rs.getString("Last_Name"));
    mITextField.setText(rs.getString("Middle_Initial"));
    pAmountTextField.setText(rs.getString("Pledge_Amount"));
    comboBox.setSelectedItem(rs.getString("Charity_Name"));




 JOptionPane.showConfirmDialog(null, "Donor " + "  " + name + "  " + lastName + "  " + middleI + " added");

}
catch (Exception ad) { 
}


}

}

View Answers

Ads









Related Tutorials/Questions & Answers:
How To Insert A New Record to MS Access table database in GUI
How To Insert A New Record to MS Access table database in GUI  Hello, I've been working on the actionPerformed part of my java application that involves inserting a record into a 6-column table in my MS Access database table. I'm
how to insert values from jsp into ms access
how to insert values from jsp into ms access   how to insert values using jsp into ms access database
Advertisements
applet connected to table in MS Access database
applet connected to table in MS Access database   i have connected my java code with the MS access database and this is my code, can anyone tell me how to show the table in an applet...pls import java.sql.
how to access the MS ACCESS database with java
how to access the MS ACCESS database with java   how to access the MS ACCESS database with java how can we insert,delete,update,search records of ms access with java   Java MS Access database connectivity Follow
how to connect to MS access database in JSP?
how to connect to MS access database in JSP?  how to connect to MS access database in JSP? Any seetings/drivers need to be set or installed before it? Please tell what needs to be done after creating a table with an example
How To Connect MS ACCESS 2003 Database in C Program with Graphics.
How To Connect MS ACCESS 2003 Database in C Program with Graphics.  How To Connect MS ACCESS 2003 Database in C Program with Graphics
How to search the table name in MS SQL Database 2005 from application
How to search the table name in MS SQL Database 2005 from application  How to search the table name in MS SQL Database 2005 from application from our helpdesk application? application might be in html
Accessing Ms access data in JAVA GUI Envi.
Accessing Ms access data in JAVA GUI Envi.  Q.How to insert data into ms access data in java using swing ? Q.How to slove (access denided ("java.lang.RuntimePermission" "accessClassInPackage.sun.jdbc.odbc")" these exception
How to Access MS Access in jar.
How to Access MS Access in jar.  how do i access my Ms-Access file... to access it via Code or is their any alter-native?? Do i need any Driver to do this ... i m able to access a Ms-access via JDBC but cant find the file wen
How to use JTable with MS-Access
How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display....   Here is an example that retrieves the data from MS Access database
How to use JTable with MS-Access
How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display....   Here is an example that retrieves the data from MS Access database
how to delete specified coloumn from database(MS Access) by using windows application
how to delete specified coloumn from database(MS Access) by using windows application  how to delete specified coloumn from database(MS Access) by using c# windows application
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database - Java Beginners
JRadioButton I want Store Information from JRadioButton to MS Access Database, and I...How to Validate JRadioButton and How to Save data from JRadioButton to MS...:access"); PreparedStatement st=con.prepareStatement("insert into names(name,age
how to insert one table to anothere table
how to insert one table to anothere table  i have insert the record one table then i retrve the value of that table i insert one value at a time
How To Display both image and data into Swing JTable which is retrieved from ms access database
How To Display both image and data into Swing JTable which is retrieved from ms access database  So far this is my code how can i display both image and data from database.. while (rs.next()) { Vector row = new Vector(columns
JComboBox Insert Edited Value Into Table
we will first create a database table (How To Create Table In MS-Access... through command prompt. To insert a value into the table we will use MS-Access... how to make JComboBox an editable and then how to insert the new edited value
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file  Hi am new to java. i need to create... in MS Access Database. the table structure is Sno JobName ProgramName Problem
How to retrieve record from table
How to retrieve record from table  Hi. I have a field in database...,kanchipuram for a single record. I have to retrieve these data from the field table.... how to do
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
retrive record from the text field and insert into to database
retrive record from the text field and insert into to database  the following code is inserting values in the my sql database but i want to insert... =new ArrayList(); String query = "insert into LTCINFO.PERSONS set
Insert Serialized Object into Database Table
Insert Serialized Object into Database Table In the previous tutorial, you... it into a file. In this section, you will learn how to Insert a serialized object into database table, deserialize it after fetching it from database table
JDBC Video Tutorial- How to insert data into MySQL database table?
remains the same. How the program works? Program uses the MySQL database...; to insert the database into database. The executeUpdate() method... the database table: CREATE TABLE `employee` (      
to get picture from ms access database by jsp-servlet....
to get picture from ms access database by jsp-servlet....  I have inserted a picture in ms access data base,,,how we can retrieve that picture by using jsp
How to insert data into MySQL Table?
How to insert data into MySQL Table?  Hi, How to insert the data into MySQL Database? Please explain me with the examples and videos thanks. Thanks   Hi, The insert into query is used to insert the data into MySQL
insert user session into other oracle database table
insert user session into other oracle database table   hello i am... comments then how i can retrive his user id using session and store id into comments table. with user id i also want to insert date and current time in to database
MS-Access
MS-Access  I am trying to upload a image to ms-acess using jsp,and my...: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect ".I think i set wrong datatype for table column in which my image going to be saved.I set
how to access database in applet
how to access database in applet  HI... I'm having an applet where we should display the database values in the applet... It works fine in the local... metadataProvider = new JdbcMetadataProvider(); private static final long
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
position.I want to save the position ( new position) in database(MySql).How...How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?  Hi members, I
how to insert value in dynamic table
how to insert value in dynamic table  i am creating a project... a dynamic table for every company.but whenever i'm inserting values to the company...=con.prepareStatement("insert into "+company+year+"(firstname,lastname,email
ms access
ms access  how to delete the autonumber from ms access using java delete code
display data from a table in Access Database in a HTML page
display data from a table in Access Database in a HTML page  how to display data from a table in Access Database in a HTML page in a Java Program

Ads