wood burning stoves 2.0*
The moose likes JDBC 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Save  data and Delete rows from JTable" Watch "Save  data and Delete rows from JTable" New topic
Author

Save data and Delete rows from JTable

Abdourahamane Toure
Greenhorn

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) {
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

Joined: Oct 27, 2005
Posts: 19649
    
  18

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


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

Joined: Oct 14, 2005
Posts: 18541
    
    8


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
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!
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Save data and Delete rows from JTable
 
Similar Threads
BMP Entity EJBs and create()
Batch Updates
LAST_INSERT_ID() with threads
Prepared Statement problem in my servlet's data manager
Inserting date into an MS Access DB