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:
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
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
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 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
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
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
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
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
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
ms access
ms access
how to delete the autonumber from
ms access using java delete code
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
Jdbc MS-Access question
Jdbc
MS-
Access question
How to delete records from the three
table in
MS-
Access? They are in relationship with each other regarding to data field