Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6058079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:33:35+00:00 2026-05-23T08:33:35+00:00

good day! I am having a problem on showing the updated version of my

  • 0

good day!

I am having a problem on showing the updated version of my database to a JTable frame…

Everything inside my JFrame were just Generated, I just follow the instruction in this link: Binding JTable with MySQL

It works properly until, I added a new JFrame for the UPDATES of the Database, when I hit the button VIEW INVENTORY(JFrame that consist the JTable showing the data at MySQL), it doesn’t show the updated version of the database.

But, after closing the Application and run the ViewInventory JFrame.. it was already Updated.

Please Help… this is the generated Code:

public class ViewInventory extends javax.swing.JFrame {

    public ViewInventory() {
        initComponents();
        setLocation(300, 120);
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        inventoryPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("inventoryPU").createEntityManager();
        itemsQuery = java.beans.Beans.isDesignTime() ? null : inventoryPUEntityManager.createQuery("SELECT i FROM Items i");
        itemsList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : itemsQuery.getResultList();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setAlignmentX(1.0F);
        jTable1.setAlignmentY(2.0F);
        jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, itemsList, jTable1);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${itemName}"));
        columnBinding.setColumnName("Item Name");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${category}"));
        columnBinding.setColumnName("Category");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${QBox}"));
        columnBinding.setColumnName("QBox");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${unitPriceBox}"));
        columnBinding.setColumnName("Unit Price Box");
        columnBinding.setColumnClass(Double.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${subTotalBox}"));
        columnBinding.setColumnName("Sub Total Box");
        columnBinding.setColumnClass(Double.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${QPc}"));
        columnBinding.setColumnName("QPc");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${unitPricePc}"));
        columnBinding.setColumnName("Unit Price Pc");
        columnBinding.setColumnClass(Double.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${subTotalPc}"));
        columnBinding.setColumnName("Sub Total Pc");
        columnBinding.setColumnClass(Double.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${grandTotal}"));
        columnBinding.setColumnName("Grand Total");
        columnBinding.setColumnClass(Double.class);
        bindingGroup.addBinding(jTableBinding);

        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Main Menu");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(jButton1)
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        new Menu().setVisible(true);
        setVisible(false);
    }                                        

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ViewInventory().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.persistence.EntityManager inventoryPUEntityManager;
    private java.util.List<inventory.Items> itemsList;
    private javax.persistence.Query itemsQuery;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration                   
}

I am sorry if I displayed everything at the generated code.

and here’s my EditItemDetails code:

try {
            Class.forName(Connect.DRIVER);
            Connection con = DriverManager.getConnection(Connect.CONNECTION_STRING,
                    Connect.USERNAME, Connect.PASSWORD);

            Statement stat = con.createStatement();

            ResultSet rs = stat.executeQuery("SELECT id, category,"
                    + "q_box, unit_price_box, sub_total_box, q_pc, "
                    + "unit_price_pc, sub_total_pc, grand_total from items WHERE "
                    + "item_name = '" + item_name_combobox.getSelectedItem() + "';");

            String category;
            int q_box, q_pc;
            double unit_price_box, sub_total_box, unit_price_pc, sub_total_pc,
                    grand_total;

            if (rs.next()) {
                q_box = rs.getInt("q_box");
                category = rs.getString("category");
                unit_price_box = rs.getDouble("unit_price_box");
                sub_total_box = rs.getDouble("sub_total_box");
                q_pc = rs.getInt("q_pc");
                unit_price_pc = rs.getDouble("unit_price_pc");
                sub_total_pc = rs.getDouble("sub_total_pc");
                grand_total = rs.getDouble("grand_total");

                double new_sub_total_box = q_box * Integer.parseInt(new_unit_price_box_txtfld.getText());
                double new_sub_total_pc = q_pc * Integer.parseInt(new_unit_price_pc_txtfld.getText());
                grand_total = new_sub_total_box + new_sub_total_pc;

            stat.executeUpdate("UPDATE items SET unit_price_box = " + new_unit_price_box_txtfld.getText()
                    + ", unit_price_pc = " + new_unit_price_pc_txtfld.getText()
                    + ", sub_total_box = " + new_sub_total_box
                    + ", sub_total_pc = "+ new_sub_total_pc
                    + ", grand_total = "+ grand_total
                    + " WHERE item_name = '"
                    + item_name_combobox.getSelectedItem() + "';");

                sub_total_box_txtfld.setText(Double.toString(new_sub_total_box));
                sub_total_pc_txtfld.setText(Double.toString(new_sub_total_pc));
                grand_total_txtfld.setText(Double.toString(grand_total));

                lblmsg.setText("Record Saved!");

                con.close();
            }
        } catch (Exception e) {
            lblmsg.setText("Error: "+ e.getMessage());
            System.out.println("Error: "+ e.getMessage());
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:33:36+00:00Added an answer on May 23, 2026 at 8:33 am

    Personally I dislike the Netbeans gui designer for a lot of reasons. It’s great for prototyping and small projects, terrible for big projects and going back in and doing maintenance. But that’s a rant for another time.

    What’s going wrong is that you’re getting back a static List from the JPA query. You need to have your GUI re-run the query after your edit event to get the updated list. The way I got this kind of thing working in the gui designer was to change the collection to an ObservableList in the “Custom Creation Code”:

    someList = Beans.isDesignTime() ? java.util.Collections.emptyList() : ObservableCollections.observableList(new ArrayList<Something>());
    

    Then when I had a gui event that updated the JTable contents, I do something like:

    someList.clear();
    someList.add(query.getResultList());
    

    I’m doing it this way because I get the list via EJB remote session bean, and I did it a long time ago in about netbeans 6.5 or 7 (the last time I used the GUI designer to create a new form). Apparently now there is a “modifiableWrapper” and “observable” you can set on the query results. That might do what you need, otherwise do it the manual way as above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day! I am having a problem in showing the data that I need
Good day everyone. I have been having the same problem all day at work
good day, i am having a bit of a problem here. i am using
Good day, I am having a little bit of a problem. I want to
Good day, I am having an interesting problem that I cannot understand. I have
Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good Day. I'm having a problem with running a ajax call before a form
Good day! I am having errors in merging/combining/concatenating arrays. For example I have arrays,
Good day, just a quick question: I would like to bind a table to
hope you're having a good day. I have been programming a IRC chatbot in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.