hi..I am really new in Java software development..I am trying to make sure that the JXTable will refresh or update the data after the save button is clicked which means that the JXTable will display the lastest data that retrieved from the database..as what I had googled through the methods to solve my problem, I had tried for 3 different methods..but they aren't work as what I expected..Besides, I noticed that the JXTable cannot have duplicated of data..but I have duplicated of data..what is the method that can be used to solve this problem?for example (I want my JXTable to look like this),
Student Name Book Name
student A abc
student A def
student A ghi
student B abc
student B def
student B ghi
below is part of my code..
private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Statement stmt = null;
try
{
Class.forName("org.postgresql.Driver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.print(e.getMessage());
}
try
{
String connectionUrl = "jdbc:postgresql://localhost:5432/abc?user=root&password=pwd";
Connection conn = DriverManager.getConnection(connectionUrl);
Object studentName = comboxstudentname.getSelectedItem();
Object bookName = comboxbookname.getSelectedItem();
stmt = conn.createStatement();
String strSQL = "INSERT INTO student (student_name, book_name) VALUES ('"+studentName+"', '"+bookName+"')";
stmt.executeUpdate(strSQL);
JOptionPane.showMessageDialog(null, "Save.");
//revalidate(); //1st method that I had tried
//repaint(); //2nd method that I had tried
//jXTable1.tableChanged(new TableModelEvent(jXTable1.getModel())); //3rd method that I had tried
stmt.close();
conn.close();
}
catch(SQLException e)
{
System.out.println("SQL Exception: "+e.toString());
}
}
thanks in advance.