• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save data and Delete rows from JTable

 
Abdourahamane Toure
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) {
try{

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

When I try to save a user entry it gives this exception
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6986)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3149)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:216)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:138)
at VisitMethods.save(VisitMethods.java:114)
refer to : ps.executeUpdate();
at VisitTable$1.actionPerformed(VisitTable.java:50)
refer to: savmthd.save(vInfo);

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

Please assist
Thanks in advance
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This error is not caused by Swing but by the database driver. Moving to JDBC.
 
Paul Clapham
Sheriff
Posts: 20989
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic