473,422 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,422 software developers and data experts.

JXTable

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..

Expand|Select|Wrap|Line Numbers
  1. private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) {                                        
  2.         // TODO add your handling code here:
  3.         Statement stmt = null;
  4.  
  5.         try
  6.         {
  7.             Class.forName("org.postgresql.Driver");
  8.         }
  9.  
  10.         catch(java.lang.ClassNotFoundException e)
  11.         {
  12.             System.err.print("ClassNotFoundException: ");
  13.             System.err.print(e.getMessage());
  14.         }
  15.  
  16.         try
  17.         {
  18.             String connectionUrl = "jdbc:postgresql://localhost:5432/abc?user=root&password=pwd";
  19.             Connection conn = DriverManager.getConnection(connectionUrl);
  20.  
  21.             Object studentName = comboxstudentname.getSelectedItem();
  22.             Object bookName = comboxbookname.getSelectedItem();
  23.  
  24.             stmt = conn.createStatement();
  25.  
  26.             String strSQL = "INSERT INTO student (student_name, book_name) VALUES ('"+studentName+"', '"+bookName+"')";
  27.             stmt.executeUpdate(strSQL);
  28.  
  29.             JOptionPane.showMessageDialog(null, "Save.");
  30.             //revalidate();   //1st method that I had tried
  31.             //repaint();      //2nd method that I had tried
  32.             //jXTable1.tableChanged(new TableModelEvent(jXTable1.getModel()));   //3rd method that I had tried          
  33.             stmt.close();
  34.             conn.close();
  35.         }
  36.  
  37.         catch(SQLException e)
  38.         {
  39.             System.out.println("SQL Exception: "+e.toString());
  40.         }
  41.     }
  42.  
thanks in advance.
Sep 20 '10 #1
0 2263

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.