0

I'm trying to display a list of data when I click on a button.

Now, I have a an homepage (a jframe that is the homepage of the program) with a button that will open the list frame and that button, when it will be clicked, will get the data from my DB and update the table.

This is the code that I've wrote on the button that is in the homepage and not in the list frame

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {  

    try {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new List().setVisible(true);
            }
        });
        this.dispose();
        String DB_URL = "jdbc:mysql://localhost:3306/registropassword?autoReconnect=true&useSSL=false";
        String DB_Username = "root";
        String DB_Password = "root";

        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(DB_URL, DB_Username, DB_Password);
        PreparedStatement prepstmt = null;
        ResultSet rs = null;
        String query = "SELECT * FROM registro";
        prepstmt = conn.prepareStatement(query);
        rs = prepstmt.executeQuery();
        jTable2.setModel(DbUtils.resultSetToTableModel(rs));
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
    }
}

NOTE:

On this line of code the jTable2, that is the name of the table that should be updated, I got a 'cannot find symbol' error on this line.

jTable2.setModel(DbUtils.resultSetToTableModel(rs));

Can someone help me to figure out where I'm wrong?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Sam
  • 35
  • 5
  • 1
    What is the error you got? An exception? A compilation error? Also i recomend you run SQL querries asynchronously because they can take quite some time to complete and that will make the GUI freeze. – fill͡pant͡ Jun 06 '16 at 14:04
  • @fillpant "cannot find symbol" I think it's because the jTable2 is in the list frame and not in the home frame but I need that the update of the list will be done with the click of the button that take me to the list frame – Sam Jun 06 '16 at 14:07
  • it's a frame that is the homepage of the program – Sam Jun 06 '16 at 14:07
  • 1) `new List().setVisible(true);` That probably does not achieve what you expect or want.. For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) *"it's a frame.."* Tip: Add @fillpant (or whoever, the `@` is important) to *notify* the person of a new comment. – Andrew Thompson Jun 06 '16 at 14:10
  • *"jTable2 is in the list frame and not in the home frame"* See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jun 06 '16 at 14:12
  • *"cannot find symbol"* On what symbol?!? These messages are not some sort of magic. You need to be able to understand what they are telling you, and take action to correct them. If you need to wait for someone else to solve every compilation error, you won't get far in programming. – Andrew Thompson Jun 06 '16 at 14:15
  • @AndrewThompson If I get the "cannot find symbol" on the jTable2 of which symbol I'm talking about? The jTable2. FFS. And I'm not waiting for someone else that will solve me the problem, I asked for help, to figure out where I'm wrong. I don't asked "SOLVE ME THE PROBLEM" – Sam Jun 06 '16 at 14:21
  • Got that out of your system? Now I suggest concentrating on that MCVE. – Andrew Thompson Jun 06 '16 at 14:51
  • @AndrewThompson I solved the problem it was just writing the code in the right place. I have created a method called Update in the list frame (that is a table lol) with the connection at the DB, the query and `jTable2.setModel(DbUtils.resultSetToTableModel(rs));` – Sam Jun 06 '16 at 14:59

0 Answers0