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 7806607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:35:27+00:00 2026-06-02T02:35:27+00:00

I used this coding to retrieve the Mysql data to the JTable.but it returns

  • 0
I used this coding to retrieve the Mysql data to the JTable.but it returns only the first data row of the relevant table of the database but then again it count the number of rows correctly and all it returns is same copy of the first row equal to the row count.

I’m new to Java and netbeans environment so if someone can help me to solve this problem i’ll be really grateful and thank you in advance 🙂

    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost/data",          "root", "1122");    
    Statement stat = (Statement) con.createStatement();
    stat.executeQuery("select * from reserve;");
    ResultSet rs=stat.getResultSet();
    ResultSetMetaData md = rs.getMetaData();
    int columnCount = md.getColumnCount();
    Vector data=new Vector();
    Vector columnNames= new Vector();
    Vector row = new Vector(columnCount);

    for(int i=1;i<=columnCount;i++){
        columnNames.addElement(md.getColumnName(i));
    }
    while(rs.next()){
    for(int i=1; i<=columnCount; i++){
    row.addElement(rs.getObject(i));
    }      
    data.addElement(row);
    }        
    DefaultTableModel model = new DefaultTableModel(data, columnNames);
    jTable1.setModel( model );     
  • 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-02T02:35:29+00:00Added an answer on June 2, 2026 at 2:35 am

    You have an error with your Vector. Consider using something like :

        Vector data = new Vector(columnCount);
        Vector row = new Vector(columnCount);
        Vector columnNames = new Vector(columnCount);
    
    
        for (int i = 1; i <= columnCount; i++) {
            columnNames.addElement(md.getColumnName(i));
        }
        while (rs.next()) {
            for (int i = 1; i <= columnCount; i++) {
                row.addElement(rs.getObject(i));
    
            }
            data.addElement(row);
            row = new Vector(columnCount); // Create a new row Vector
        }
        DefaultTableModel model = new DefaultTableModel(data, columnNames);
        jTable1.setModel( model );     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be really simple but I'm not used to this way of coding
I had used the SqlDataSource to retrieve data from database to gridview. <asp:SqlDataSource ID=SqlDataSource1
I used this coding to send mail using gmail, but am getting the below
I used this code to compare two NSNumber objects, but it never passed the
I used this example : http://woork.blogspot.com/2007/10/insert-record-into-database-using-ajax.html it is working when using with Numbers for
I used this code to change the annotation's color,but after that,the title and subtitle
I used this code previously in netbeans 6.9.1 but it does not seem to
I have always used rawurlencode to store user entered data into my mysql databases.
I'm asking this question because it isn't the first time I saw this coding
So far i have used this coding for view formy mvc contrib grid....here the

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.