File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Save  data and Delete rows from JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Save  data and Delete rows from JTable" Watch "Save  data and Delete rows from JTable" New topic

Save data and Delete rows from JTable

Abdourahamane Toure

Joined: Feb 08, 2010
Posts: 2
Hello everyon!
Please help me on this
I want to save data to my database from my JTable
here is the code for the save method

called here
SaveBtn = new JButton("Save Row");
SaveBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {

Visit vInfo = new Visit();
VisitMethods savmthd = new VisitMethods();;
model.fireTableRowsUpdated(0, visittable.getSelectedRow()+1);
}catch(Exception ex){

When I try to save a user entry it gives this exception
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(
at sun.jdbc.odbc.JdbcOdbc.standardError(
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(
refer to : ps.executeUpdate();
at VisitTable$1.actionPerformed(
refer to:;

Please take a look at this is it right???

Please assist
Thanks in advance
Rob Spoor

Joined: Oct 27, 2005
Posts: 20275

This error is not caused by Swing but by the database driver. Moving to JDBC.

How To Ask Questions How To Answer Questions
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Because you created a new Visit object and didn't put any data into it. Have a look at the code following

and you will see where the "blank" data is coming from.
Abdourahamane Toure

Joined: Feb 08, 2010
Posts: 2

I now know that those blank lines come from the empty assignments I did. So i'm thinking of a parameterised constructor with 5 paramters that I'm going to assign to the instance fields like this

But my concern is the values are entered in the JTable row not in textfields, if it were textfields I could call the Parameterised constructor with 5 variables for which the values would be the values of the textfields.

So please help on how do this with JTable!
I agree. Here's the link:
subject: Save data and Delete rows from JTable
jQuery in Action, 3rd edition