IntelliJ open source
[Logo] JavaRanch » Big Moose Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JDBC
 
RSS feed
 
New topic
Author

Save data and Delete rows from JTable

Abdourahamane Toure
Greenhorn

Joined: Feb 08, 2010
Messages: 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) {
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 Prime
Bartender

Joined: Oct 27, 2005
Messages: 8845

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

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Messages: 7199


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

Joined: Feb 08, 2010
Messages: 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!
Thanks.
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JDBC
 
RSS feed
 
New topic
JProfiler
Get rid of your performance problems and memory leaks!

.