Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9151029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:42:05+00:00 2026-06-17T11:42:05+00:00

Adding the colums works, but i am stuck when i want to add the

  • 0

Adding the colums works, but i am stuck when i want to add the data of the columns stored in a mysql database to the jtable. it ask for a object vector[][] but i have no clue what to give

Connection con;
DefaultTableModel model = new DefaultTableModel();

public Hoofdscherm() {
    initComponents();
    uitvoerSpelers.setModel(model);

    try {
        con = DriverManager.getConnection("jdbc:mysql://localhost/fullhouse", "root", "hamchi50985");

        // selecteer gegevens uit fullhouse.speler tabel
        PreparedStatement stat = con.prepareStatement("SELECT * FROM fullhouse.speler");

        // sla deze GEGEVENS op in een resultset
        ResultSet resultaat = stat.executeQuery();

        // haal alle kolomnamen op PUUR VOOR DE MODEL VAN JTABLE 
        ResultSetMetaData data = resultaat.getMetaData();

        String[] colum = new String[15];
        for (int i = 1; i < data.getColumnCount(); i++) {
            colum[i] = data.getColumnName(i);
            model.addColumn(colum[i]);
            while (resultaat.next()) {
                Object[] gegevens  = new String[] {resultaat.getString(1)};
                model.addRow(gegevens[0]);
            }
        }    
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:42:06+00:00Added an answer on June 17, 2026 at 11:42 am

    I think you need something like this.

    Note
    1. Also add your columns separate to resultset data. Like I showed in my code below.

    Vector<String> rowOne = new Vector<String>();
    rowOne.addElement("R1C1");
    rowOne.addElement("R1C2");
    
    Vector<String> rowTwo = new Vector<String>();
    rowTwo.addElement("R2C1");
    rowTwo.addElement("R2C2");
    
    Vector<String> cols = new Vector<String>();
    
    Vector<Vector> vecRow = new Vector<Vector>();
    vecRow.addElement(rowOne);
    vecRow.addElement(rowTwo);
    cols.addElement("Col1");
    cols.addElement("Col2");
    JTable table = new JTable(vecRow, cols);
    

    Edit

    For you convenience and requirement You can follow code structure below.

     Vector<String> rows = new Vector<String>();
     Vector<Vector> dBdata = new Vector<Vector>();
    
    // Add Columns to table
    for (int i = 1; i < data.getColumnCount(); i++) {
        colum[i] = data.getColumnName(i);
        model.addColumn(colum[i]);
    }
    
    while (resultaat.next()) {
        // add column data to rows vector
                // Make sure that all data type is in string because of generics
        rows.add(resultaat.getString("columnName1"));
        rows.add(resultaat.getString("columnName2"));
        rows.add(resultaat.getString("columnName3"));
    
        // add whole row vector to dBdata vector
        dBdata.addElement(rows);
    }
    model.addRow(dBdata);
    

    Vector implements a dynamic array. It is similar to ArrayList, but with two differences:

    1. Vector is synchronized.

    2. Vector contains many legacy methods that are not part of the collections framework.

    Class Vector Javadoc

    I hope this will help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we've been making changes in the MySQL database, adding tables, columns and so forth
I am adding columns to a datagrid view using a variable UserVGrid.Columns.Add(newline[1], newline[1]); Which
I am dynamically adding columns to a table by using document.createElement(th) var newTH =
I understand that when adding a column to a table containing data in SQL
I have situation where I need to change the order of the columns/adding new
I want to update a column by adding a new value alongside the old
Should I be careful adding too many include columns to a non-cluster index? I
I'm trying to make NSTable view app with adding rows with two columns x
I am dynamically creating a RadGrid and adding GridTemplateColumns to it. Those columns have
I have 40+ columns in my table and i have to add few more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.