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

  • Home
  • SEARCH
  • 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 8330081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:00:37+00:00 2026-06-09T02:00:37+00:00

I have a Java application that connects to a MySQL database and uses a

  • 0

I have a Java application that connects to a MySQL database and uses a select statement to display rows whose status is “O” through a JTable. I have added a mouse event so that once the selected row is clicked, the details of the row are displayed in another GUI form. After a mouse event on the new form, the database table is updated to status “R”. When I go back to the original display on the JTable, I expect the row to no longer be displayed. However, I find the row I had selected earlier still displayed on the JTable and I have to exit the entire program for the JTable to refresh with the updated status.

The table status is getting updated to “R” and am using

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

to navigate from each form. Is there a way to refresh the database connection so that once I go back to the display GUI, the table updates using the changed status?

I display using this code:

public class ReceiveOrderedParts extends JFrame{
static Vector<Vector<String>> data = new Vector<Vector<String>>();
static JTable table;
ReceiveOrderedParts(final String st) throws InterruptedException, SQLException{             
    super("Order Details Inquiry");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel topPanel = new JPanel();

    getContentPane().add(topPanel, BorderLayout.PAGE_START);

    Vector<String> headers = new Vector<String>();
    headers.add("Order Number");
    headers.add("Date");       
    headers.add("Part Number");
    headers.add("Part Name");
    headers.add("Application");
    headers.add("Quantity");  
    headers.add("Total Cost");
    headers.add("Supplier");                       
    headers.add("Country");

    getData();

    //this is the model which contain actual body of JTable
    DefaultTableModel model = new DefaultTableModel(data, headers);
    table = new JTable(model);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);       
    //table.enable(false);
    table.addMouseListener(new ReceiveOrderedParts.MyMouseAdapter());
    boolean b = table.isCellEditable(WIDTH, WIDTH);
    b = false;

    header_size();

    JScrollPane scroll = new JScrollPane(table);

    scroll.setHorizontalScrollBarPolicy(
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

    getContentPane().add(scroll, BorderLayout.PAGE_START);

    pack();
    setResizable(false);
    setVisible(true);
    setSize(1000, 700);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public class MyMouseAdapter extends MouseAdapter  {

    public void mousePressed(MouseEvent e)  {         
            int colIdx = table.columnAtPoint(e.getPoint());                
            int rowIdx = table.rowAtPoint(e.getPoint());
           Object obj = table.getModel().getValueAt(rowIdx, colIdx) ;
              String order = obj.toString();                
            JOptionPane.showMessageDialog(null,"Receive Order "+ order + "?", "Success",
                        JOptionPane.INFORMATION_MESSAGE);
                   // return;
        try {
            SelectOrder seo = new SelectOrder(order);
            seo.setVisible(true);
            setVisible(false);
        } catch (InterruptedException ex) {
            Logger.getLogger(ReceiveOrderedParts.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

/**
 * Setting the particular Column Size in JTable
 */
public static void header_size() {
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setPreferredWidth(100);

    column = table.getColumnModel().getColumn(1);
    column.setPreferredWidth(100);
}

/**
 * Fetching Data From MySql Database and storing in a Vector of a Vector to
 * Display in JTable
 */
private static void getData() throws SQLException {
    // Enter Your MySQL Database Table name in below Select Query.
    String str = "select order_number, Part_number, spare_desc, vehicle_app, qnty_ordered,"
            + "seller_name, total_purchases, country, order_date from order_details_table where status = 'O'";
    Connection cn = null;
    ResultSet rs;
    Statement st;

    try {
        // Change the database name, hosty name, 
        // port and password as per MySQL installed in your PC.
        cn = DriverManager.getConnection("jdbc:mysql://"
                + "localhost:3306/test", "root", "gatungo@123");
        st = cn.createStatement();

        rs = st.executeQuery(str);

        while (rs.next()) {
            Vector<String> d = new Vector<String>();

            d.add(rs.getString("order_number"));
            d.add(rs.getString("order_date"));                
            d.add(rs.getString("Part_number"));
            d.add(rs.getString("spare_desc"));
            d.add(rs.getString("vehicle_app"));
            d.add(rs.getString("qnty_ordered"));  
            d.add(rs.getString("total_purchases"));
            d.add(rs.getString("seller_name"));                                                
            d.add(rs.getString("country"));

            d.add("\n\n\n\n\n\n\n");
            data.add(d);

        }
        cn.close();

    } catch (SQLException e) {

        e.printStackTrace();

    }
}
}

I go back with this code;

Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
conn = DriverManager.getConnection(url + db, "user", "password");
Statement st = conn.createStatement();
String partno = tpart.getText();
String sparedesc = tdesc.getText();
String vapp = tapp.getText();
String qunty = tqnty.getText();
String costper = tcost.getText();
String country = tcountry.getText();
String retail = tretail.getText();
String store = tstore.getText();
String location = tlocation.getText();
String rdate = trdate.getText();
String storeit = "INSERT INTO Store_info_table (Part_number, spare_desc, vehicle_app, qnty_received, cost_per_unit"
        + ", selling_price, country, store_name, store_location, recvd_date) "
        + "VALUES ('" + partno + "', '" + sparedesc + "', '" + vapp + "', '" + qunty + "', '" + costper + "','" + retail + "','" + country + "','" + store + "','" + location + "','" + rdate + "' )";
st.execute(storeit);

String updateOrder = "UPDATE order_details_table set status = 'R' where order_number = '" + order + "'";
st.execute(updateOrder);

JOptionPane.showMessageDialog(null,"Item Stored Successfully", "Success",
        JOptionPane.INFORMATION_MESSAGE);
conn.close();

ReceiveOrderedParts rop = new ReceiveOrderedParts(order);
rop.invalidate();
rop.setVisible(true);
setVisible(false);                        
  • 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-06-09T02:00:38+00:00Added an answer on June 9, 2026 at 2:00 am

    You should consider implementing observer pattern to handle this situation. So when data in your new form is updated, a notification is sent and the original table is updated by fetching new values from the database.

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

Sidebar

Related Questions

I have developed a Java Application that connects with a database (insert, select ...)
I have created a java SE application that uses the mysql database using mysql
We have a java application that connects to mysql database. We are now going
I have a java application that connects to a Sybase database. I want to
I have an Java application that connects to database. In the production environment, the
I have a java application that connects to a database. The user name and
I have an application in java that uses two different threads.And for sharing data
I am writing a Java JDBC database application that connects to an Oracle 11g
I have a java application that uses jtds driver and commons-dbcp as a connection
I have a client/server application that remotely connects to a server via Java's SSLSocket.

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.