This is a brain-cracking experience with JTable
binding. Here's what I did. I created a JTable
with columns set to a specified width, formatted it using renderers
, and added some codes on it. But when i try to bind it to a model, all the columns were replaced by the fields of the model. Is there a way on how to correctly bind it?
I'm avoiding loops because there are 100+ thousand records in the database. I'm trying to use other methods such as BeansBinding
and EntityManager
but I don't know how to change the datasource (that's why i choose binding it to a model) because I'm testing this to backup database and soon to be implemented to the new server.
This is what I did in .Net
, I usually create a datagridview and binded it to a dataset and it works fine. But i cannot apply it to java. I need your opinion on how can I do it in java that can handle 100+ thousand records.
PreparedStatement pst = conn.prepareStatement("SQL Query here");
ResultSet rs = pst.ExecuteQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
The code above works fine but my very very big problem on this is that it overrides my formatted columns by the columns in the model.
Please help me on this.
Based on the comments, you could try to add the following method to DbUtils:
and then your code would became:
l have discovered that you can create your formatting method and call it after the try block as below.
This will work perfectly
too wide question
1) never, really never put
100+ thousand records
to the view, and this is valid for all programing languages, is really useless2) (my view) BeansBindings are out_dated use standard TableModel instead
3) nothing better as @camickr TableFromDatabase is around, or another suggestion is searching for
ResultSetTableModel