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 8632891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:24:49+00:00 2026-06-12T09:24:49+00:00

I’m having a problem while updating cell value of the JTable. What i want

  • 0

I’m having a problem while updating cell value of the JTable. What i want to do is after selection of a particular cell from the JTable, i should be able to edit and the action must reflect the database at the back end. I’m using HSQL. My table has 4 columns with one PK.
Kindly give me an alternative and/or provide me with some code by replacing the * s. I’m new just a beginner.

d_view.addActionListener(new ActionListener() { //----action listener of a button
    public void actionPerformed(ActionEvent po) {
        try {
            Connection connec;
            Class.forName("org.hsqldb.jdbcDriver");
            connec = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/","SA", "");
            java.sql.Statement stt=connec.createStatement();
            ResultSet rs=stt.executeQuery("select * from DepReg");//----------TO VIEW DATA IN TABULAR FORMAT
            ResultSetMetaData rt=rs.getMetaData();
            int cols=rt.getColumnCount();
            String c[] =new String[cols];
            for(int i=0;i<cols;i++){
                c[i]=rt.getColumnName(i+1);
                dm.addColumn(c[i]);
            }
              Object row[]=new Object[cols];
                while(rs.next()){
                     for(int i=0;i<cols;i++){
                            row[i]=rs.getString(i+1);
                        }
                    dm.addRow(row);
                }
                table.setModel(dm);
                connec.close();
            }
        catch (Exception ty) {}
    }
});//--------HERE THE PROBLEM STARTS
table.getModel().addTableModelListener(new TableModelListener() {
    public void tableChanged(TableModelEvent tme) {
        int rows=tme.getFirstRow();
        int colms=tme.getColumn();
        TableModel model=(TableModel)tme.getSource();
        String colname=model.getColumnName(colms);
        Object data=model.getValueAt(rows, colms);
//*********EDIT/REPLACE THE CODE ***************//
        try {
            Connection connec;
            Class.forName("org.hsqldb.jdbcDriver");
            connec = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/","SA", "");
            java.sql.Statement stt=connec.createStatement();
//-----------I WILL INCLUDE AN UPDATE STATEMENT OVER HERE BASED ON THE VALUE SELECTED
        }
        catch (Exception ae) {}
        }
});
  • 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-12T09:24:49+00:00Added an answer on June 12, 2026 at 9:24 am
    • Database connections should not happen on the Event Dispatch Thread. They are simply too slow. Move that to a background thread. See the Swing concurrency tutorial for more info
    • Not completely clear to me whether you are already capable of editing your table, but if not, this is achieved by making sure in the TableModel that the isCellEditable method returns true for the cells you want to be editable, and that you have set a TableCellEditor on your JTable
    • Instead of adding a TableModelListener to update your database I would move that logic to a custom TableModel. Every time the setValueAt method is called, you know changes have been made. You can then update the database (again, not on the Event Dispatch Thread).
    • If the database can be updated from other places as well, you probably will want to poll the database at certain moments in time to update your TableModel to reflect the latest state of the database. Make sure you do the polling on a worker thread. Then you can either create a brand new TableModel on the worker thread, and replace the TableModel of the table on the Event Dispatch Thread. Or you can update the existing model on the EDT (do not forget to fire events, or if your model extends from DefaultTableModel/AbstractTableModel you can use the available API).

    I also recommend reading the Swing table tutorial for more info.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.