views:

277

answers:

2

Continuing this question.

My problem is that I can not edit my JTable. I get an exception and the Object value instead of what I should be seeing.

I am using the ResultSet Table code with a MS-Access database and with a few modifications. My code can be found here. I run into an error when I rs.updateRow() is called. java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Error in row.

I did a google search on this error with updateRow() and not much came up. The only real answer I saw was to use a prepared statement but I am not a pro with SQL commands.

Also a plus if you could tell me the best approach in making this become a GlazedList so I can filter easily. Unless you can provide me something that filters regular JTables easily.

+1  A: 

I am using the ResultSet Table code

Search the web for a better example of a ResultSetTableModel. I'm sure you will find one that already implements the setValueAt(...) method. Or another approach is to just copy the data from the ResultSet to a DefaultTableModel and then you can edit it no problem.

Unless you can provide me something that sorts regular JTables easily.

Have you read the JTable API and followed the link to the Swing tutorial on "How to Use Tables" which contains a working example of sorting, since sorting is a default part of the JDK.

camickr
Whoops. I meant filtering multiple values. Would the DefaultTableModel method keep the database up to date? I still get the error with the google searched setValueAt
twodayslate
The tutorial shows how to do filtering. No the DefaultTableModel doesn't automatically update the database (but neither does your current model) . Just add a TableModelListener to the model and you can update the database yourself. Otherwise I think you will need to get a 3rd party package to support this.
camickr
Do you know of any 3rd party packages that can accomplish all of this?
twodayslate
+1  A: 

Trying to offer more help since the initial solution didn't work 100%.

Try the info here: Updatable ResultSets to see how to make your ResultSet updatable by specifying arguments when creating a Statement object from your Connection. I realized this option may not have been set by default for you. If you driver supports this mode, it should allow the code to work.

EDIT: It's not necessarily the driver (though you will need a JAR if you wish to change that). You need to enable ResultSet.TYPE_SCROLL_SENSITIVE when creating the table -- the driver may still support this mode. There are ways to probe what the JDBC driver supports, but they're kind of a pain to use unless you use a GUI like SquirrelSQL Client to get a full list of capabilities.

BobMcGee
Thank you for the continued help! How would I change drivers? I am currently using `sun.jdbc.odbc.JdbcOdbcDriver`. I tried to use `com.pointbase.jdbc.jdbcDriver` but it doesn't work. I need a jar? In the link you gave - my program threw an error at `ResultSet.TYPE_FORWARD_ONLY` so it must be the driver that is making the issue?
twodayslate
@twodayslate: see edit.
BobMcGee
I still get the Error in Row when I change it to SENSITIVE. When you had your code working... what driver did you use? In the example they used com.pointbase.jdbc.jdbcDriver but I could not find a jar for MS-Access.
twodayslate
I was using the H2 DBMS driver... wouldn't touch Access with a 3 meter pole. To get my version to work, you'll absolutely have to find a JDBC driver (yes JAR) for Access that supports more of the JDBC features. It sounds like your Access driver is pretty bare-bones.
BobMcGee