Results 1 to 5 of 5
  1. #1
    Azuxard is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default 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!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Best of luck

  3. #3
    Azuxard is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    [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?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

Similar Threads

  1. Replies: 7
    Last Post: 09-26-2011, 11:29 PM
  2. ResultSet.updateRow() problem
    By kvikas in forum Advanced Java
    Replies: 1
    Last Post: 04-22-2008, 03:11 AM
  3. problem with ResultSet.updateRow()
    By kvikas in forum New To Java
    Replies: 0
    Last Post: 04-14-2008, 10:00 AM
  4. Problem in adding sound.
    By shanky_sanks in forum Java Applets
    Replies: 6
    Last Post: 03-29-2008, 08:37 PM
  5. BlackJack help please,, adding hand values
    By javakid9000 in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 04:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •