Hi All,

I have a Jtable with six columns. I am displaying the contents of my database into my Jtable. Its working fine.

But I am facing trouble updating the changes done in Jtable cells to appropriate database cell.

In the below code when I tried to edit the First Row ,third column in my Jtable, it does not get reflected in the First row, third column in my database, Indeed im getting an error "Column count doesn't match value count at row 1".

Here is my code which I created the JTable using defaultTable Model.

Thanks in Advance.

public void tableChanged(TableModelEvent e) {
    // TODO Auto-generated method stub

    if(e.getType()==TableModelEvent.UPDATE){

        Object value =  dm.getValueAt(e.getFirstRow(), e.getColumn());

        try {
            statement =(Statement) dbConnection.createStatement();

    int count = statement.executeUpdate ("INSERT INTO incident VALUES ('"+value+"')");



        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }


    }

Recommended Answers

All 7 Replies

If you do not specify the columns in an SQL insert query, you'll need to specify values for ALL columns in that table.

insert

If you do not specify the columns in an SQL insert query, you'll need to specify values for ALL columns in that table.

Hi pritaeas,

But User is only updating one cell which is in one column, I save that into an object for updating in database . how can I specify values for all Columns ? . Please explain.

That cross-posted version shows two different versions of the SQL satement (both different from this one), so until OP gets his head straight we're all just chasing will-o-the-wisps here.

There is a Syntax error in that post... The code which i posted here is the correct one..

First i googled this query and found few topics in SO but i could not find exact answer Thats why i posted in SO .

is posting same topic in other forums wrong ? i really dont know....

It's considered rude to post the same problem in two forums without letting peopleknow that's what you've done. That's because people on one forum could be wasting their time trying to solve your problem when it has already been solved in the other forum.

The syntaxes in the other forum were more nearly right - you need to specify which columh you are updating, but in the first version you have an extra comma, and in the second you omitted a pair of (). Check your SQL reference for the correct syntax.

people on one forum could be wasting their time trying to solve your problem when it has already been solved in the other forum.

Oh Ok. I didnt know this, Hereafter I will update if i post in other forum. Closing this request henceforth.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.