Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JTable not updating with result set

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JTable not updating with result set

    Hi all,
    I have a method in a GUI class which recieves a resultSet.
    I am trying to get my existing JTable to update with data from the result set.
    I can see the table columns ( I am only using 2 columns from the resultset ), however when I try to iterate I am only getting one result back to the table model. There should be more.
    There are no errors during execution.

    If someone could help with this issue it would be much appreciated.

    Please see the code below.

    public static void getResultSet(ResultSet resultSet) throws SQLException {

    ResultSetMetaData metaData = resultSet.getMetaData();
    Vector<String> columnNames = new Vector<String>();

    int columnCount = 2;
    for (int column = 1; column <= columnCount; column++) {
    columnNames.add(metaData.getColumnName(column));
    System.out.println("ColumnNames "+columnNames );
    }

    DefaultTableModel datamodel = new DefaultTableModel(columnNames, 0);
    resultsTable.setModel(datamodel);

    while (resultSet.next()) {
    Vector<String> vector = new Vector<String>();
    for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
    vector.add(resultSet.getString(columnIndex));
    }
    datamodel.addRow(vector);
    System.out.println("VECTOR = " +vector);


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,051
    My Mood
    Mellow
    Thanks
    184
    Thanked 650 Times in 637 Posts

    Default Re: JTable not updating with result set

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers, including a few "house rules" that you'd try to follow when visiting someplace new.

Similar Threads

  1. Implementation of methods of Result Set
    By vijay15.java in forum JDBC & Databases
    Replies: 2
    Last Post: November 21st, 2013, 01:33 PM
  2. [SOLVED] SwingWorker updating JTABLE ...
    By harshilshah in forum AWT / Java Swing
    Replies: 2
    Last Post: April 30th, 2013, 11:41 PM
  3. JDBC - any query and the corresponding result set
    By moekler in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 19th, 2012, 04:15 PM
  4. Result set is closed
    By keshav_agrawal89 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 11th, 2011, 08:35 AM
  5. result set array button
    By dread_arisawa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 21st, 2010, 10:05 AM

Tags for this Thread