Results 1 to 5 of 5
- 03-31-2009, 07:53 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 5
- Rep Power
- 0
Problem when adding values of the ResultSet to a AbstractTableModel
Hi everyone!
The reason of this post if I do not know how to put the values of the resultset (a query of SQL Server 2005) in an AbstractTableModel extended class.
I used to make object[][] and String[] in order to fill them with the data of the ResultSet and then add them to the JTable, but that was when I declared the JTable as: JTable tab = new JTable(obj,strg); I heard that there is an easier way to do that, just by sending the ResultSet from my actual class, for example, catalogue, as a parameter to the model class. I did that and also made some of the procedures that it asked for, for example: getColumnCount()... but when I execute my project it just doesn't works, well, all works but the table doesn't appear.
As an extra information, what I do in my catalogue class is:
catModelo = new Modelo(rs);
JTable tablas = new JTable(catModelo);
So it calls the model: Modelo, and it suppossed to work, but do not, what I'm doing wrong?
Thanks since now for any help!
-
I'm no guru in JTables, and this may not be your exact problem, but usually you're far better off extending a DefaultTableModel object rather than the AbstractTableModel object. If you do the former, many of the model's necessary methods will be created for you.
If this doesn't help, you may wish to post some of your pertinent code.
Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
Best of luckJava Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
- 04-01-2009, 12:04 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 5
- Rep Power
- 0
[code]
// public Modelo(ResultSet mod_rs)
// {
// fireTableDataChanged();
// md_rs = mod_rs;//md_rs receives mod_rs(both ResultSet)
// try
// {
// md_rs.last(); //How many rows exist in md_rs
// conteoRows=md_rs.getRow();
// md_rsmd=md_rs.getMetaData();
// }
// catch(Exception md_ex)
// {System.out.println("error en: "+md_ex);}
// }
//public int getColumnCount()
// {
// int col=0;
// try
// {
// col = md_rsmd.getColumnCount();
// }
// catch(Exception md_ex1)
// {System.out.println("erron en: "+md_ex1);}
// return col;
// }
//
// public int getRowCount()
// {
// return conteoRows;
// }
[code]
That was the constructor of my class Modelo. I implement some other methods there... now the part where I call to the method is:
[code]
//catModelo = new Modelo(rs);
//JTable tablas = new JTable(catModelo);
//catPanel.add(tablas);
[code]
That was in another class called Catalogo, then I add the catPanel(which is a JPanel) to an InternalJFrame... but when I execute the main project, all seems to be fine until it went to the part of showing the JTable, it just didn't happen, I did not get any Exception, so I think the problem is that the JTable is empty. How do I put there the data of the ResultSet into the AbstractTableModel?
-
I'm sorry, but I'm finding your code difficult if not impossible to read, and you might want to reformat it . Please note the difference between the code tag on the top and the one on the bottom. Also, why is it completely commented out?
- 04-01-2009, 02:03 AM #5
Similar Threads
-
adding values from file to multi-dimensional ArrayList
By sebo in forum New To JavaReplies: 7Last Post: 09-26-2011, 11:29 PM -
ResultSet.updateRow() problem
By kvikas in forum Advanced JavaReplies: 1Last Post: 04-22-2008, 03:11 AM -
problem with ResultSet.updateRow()
By kvikas in forum New To JavaReplies: 0Last Post: 04-14-2008, 10:00 AM -
Problem in adding sound.
By shanky_sanks in forum Java AppletsReplies: 6Last Post: 03-29-2008, 08:37 PM -
BlackJack help please,, adding hand values
By javakid9000 in forum New To JavaReplies: 1Last Post: 11-18-2007, 04:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks