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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:33:35+00:00 2026-05-24T16:33:35+00:00

i want to add all my data from DB to jtable, but using this

  • 0

i want to add all my data from DB to jtable, but using this code i get only the last row from DB, added to the table severelal times.
Can someone tell where is mistake?

public Vector getOrder() throws Exception
{ 
    DbConnection();
    Statement st = null;
    ResultSet res =null;
    String query="Select * From Orders;";

try{
    st=connect.createStatement();
    res=st.executeQuery(query);
    Vector v =new Vector();
    Vector<String> record = new Vector<String>();
    int i=0;
    while(res.next())
    { 
    record.clear();
        uzsakNr=res.getString("Uzsakymo_nr");           
        priemDat=res.getString("Priemimo_data");
        irengPav=res.getString("Irenginio_pavadinimas");
        model=res.getString("Modelis");
        status=res.getString("Statusas");
        grazDat=res.getString("Grazinimo_data");
        clientId=Long.toString(res.getLong("ClientId"));

        //record.addElement(i);
        record.addElement(uzsakNr);
        record.addElement(priemDat);
        record.addElement(irengPav);
        record.addElement(model);
        record.addElement(status);
        record.addElement(grazDat);
        record.addElement(clientId);
        //record.addElement("");
        v.addElement(record);       
        i++;
    }
    //Zle vydaji, daji tyko trzy takiesame ostatnie
    System.out.println(v);
    return v;
}finally {
    if(res!=null) res.close();
    if(st!=null) st.close();
}

}

in another class

        try{
        Vector ve=db.getOrder();

        String heading[]={"uzsakNr","priemDat","irengPav","model","status","grazDat","ClientID"};
        Vector columnHeads= new Vector();
        for (int i=0;i<heading.length; i++)
            columnHeads.addElement(heading[i]);

        table = new JTable(ve,columnHeads);
        table.addMouseListener(new TableMouseListener());
        scrollPane.setViewportView(table);
        UzsakPanel.add(scrollPane);
        scrollPane.setBounds(10, 10, 901, 200);
        }catch(Exception e2){e2.printStackTrace();}
  • 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-05-24T16:33:35+00:00Added an answer on May 24, 2026 at 4:33 pm

    Firstly,

    Replace the line containing clear() with Vector<String> record = new Vector<String>();

    Secondly, I think what you’re doing is probably correct but your printing is the problem.

    Since you have a vector of vectors containing strings, I would print it like so

    for(Vector stringVect : v) {
        for(String s : stringVect) {
            System.out.print(s+ '\t');
      }
      System.out.println();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What if I want not only to add events for all future added, but
I think the title tells it all: I want to add a row to
I am trying to get all the data from a combo-box in vb. Lets
Basically I want a list view(CheckBox and TextView) that has all the data from
I have a button with a jquery code that clears all data from a
Expanding on recent_posts_on_self below, I want to add an all_recent_posts_on_self method but I'm not
I want to add a bar right below NavigationController which will visible all the
when asp.net output a page ,I want to add some same parameters for all
I want to access all the files in a folder to add to a
All I want to know is if there's an easy way to add lines

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.