First of all, sorry for my poor English. I will try my best to understand your problem.
All I want to do is save the new data that the user entered in JTable when the "Save" button is clicked.
I extract the student ID, the name in the first two columns from the database, and also add the current date in the third column and absinthe / present as the fourth column that can be edited. I have the following code to retrieve data from a database.
**Attendance.java** : package shreesai; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.text.SimpleDateFormat; import java.util.Vector; public class Attendance{ Connection con = Connectdatabase.ConnecrDb(); java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime()); SimpleDateFormat fromUser = new SimpleDateFormat("dd/MM/yyyy"); String d1 = fromUser.format(sqlDate); String d = d1.toString(); public Vector getEmployee()throws Exception { Vector<Vector<String>> employeeVector = new Vector<Vector<String>>(); PreparedStatement pre = con.prepareStatement("select studentid,name from student"); ResultSet rs = pre.executeQuery(); while(rs.next()) { Vector<String> employee = new Vector<String>(); employee.add(rs.getString(1));
** AttendanceGUI.java: **
package shreesai; import static java.awt.Frame.MAXIMIZED_BOTH; import java.sql.Connection; import java.util.Vector; import javax.swing.JOptionPane; public class AttendanceGUI extends javax.swing.JFrame { Connection con = Connectdatabase.ConnecrDb(); private Vector<Vector<String>> data; private Vector<String> header; public AttendanceGUI() throws Exception { this.setLocationRelativeTo(null); setExtendedState(MAXIMIZED_BOTH); Attendance att = new Attendance(); data = att.getEmployee(); header = new Vector<String>(); header.add("Student ID"); header.add("Student Name"); header.add("Date"); header.add("Absent/Present"); initComponents(); } @SuppressWarnings("unchecked")
This output I get when I run JFrame:

Now, what I really want, every time the user will edit the data in JTable, as in the following image:

**** After clicking the “Save Attendance” button, the current JTable values should be entered into the database. I use the Sqlite database, which is an addon in Firefox. I created an attendance table in my database that has an integer number of students, name varchar, date DATETIME, and preab VARCHAR (to store whether a particular student was present or absent) ****
I hope you get my problem. Thanks in advance.
source share