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

  • Home
  • SEARCH
  • 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 6146931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:01:51+00:00 2026-05-23T19:01:51+00:00

there’s my code, it doesn’t work because shows emty table without any rows ir

  • 0

there’s my code, it doesn’t work because shows emty table without any rows ir columns
can someone tel where is problem

public class test extends JFrame {

    private final JButton pridetiNaujaButton = new JButton();
    private final JButton pasalintiButton = new JButton();
    private final JButton redagotiButton = new JButton();
    private final JButton paieskaButton = new JButton();
    final GtFromDb baz=new GtFromDb();
    private Vector <Vector<String>> data;
    private Vector<String> header;
    private final JScrollPane scrollPane = new JScrollPane();
    private final JTable table = new JTable(data,header);
    public static void main(String args[]) {
        try {
            test frame = new test();
            frame.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * Create the frame
     */
    public test() {
        super();
        setBounds(100, 100, 781, 412);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        try {
            jbInit();
        } catch (Throwable e) {
            e.printStackTrace();
        }


            GtFromDb db=new GtFromDb();
            try {
                data=db.getClient();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }           
            header=new Vector<String>();
            header.add("Imones pavadinimas");
            header.add("vardas");
            header.add("pavarde");
            header.add("salis");
            header.add("Adresas");
            header.add("telefonas");
        }


    private void jbInit() throws Exception {
        getContentPane().setLayout(null);

        getContentPane().add(pridetiNaujaButton);
        pridetiNaujaButton.setText("Prideti nauja");
        pridetiNaujaButton.setBounds(0, 0, 106, 26);

        getContentPane().add(pasalintiButton);
        pasalintiButton.setText("Pasalinti");
        pasalintiButton.setBounds(112, 0, 106, 26);

        getContentPane().add(redagotiButton);
        redagotiButton.setText("Redagoti");
        redagotiButton.setBounds(224, 0, 106, 26);

        getContentPane().add(paieskaButton);
        paieskaButton.setText("Paieska");
        paieskaButton.setBounds(336, 0, 106, 26);

        getContentPane().add(scrollPane);
        scrollPane.setBounds(10, 48, 745, 316);     
        scrollPane.setViewportView(table);

    }
    public class GtFromDb
    { Connection connect;
      Statement zadanie;
      String sql;
      ResultSet dane;
    //  Map<String,String> carmap =new HashMap<String,String>();
    //  Map<String,String> ownmap =new HashMap<String,String>();
    void DbConnection() throws SQLException
    {
        String baza="jdbc:odbc:dielektric_repair";
        try
        {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }catch(Exception e){System.out.println("Connection error");}
        connect = DriverManager.getConnection(baza,"","");
    }
    public Vector getClient() throws Exception
    {
    Vector <Vector<String>> clientVector=new Vector<Vector<String>>();  
    try
    {DbConnection();
    PreparedStatement zadanie = connect.prepareStatement("SELECT * FROM Clients");

    dane = zadanie.executeQuery();
    while(dane.next()) {
    Vector <String> client=new Vector<String>();
     String imonesPav=dane.getString("Imones_pavadinimas");
     String vardas = dane.getString("Vardas");
     String pavarde = dane.getString("Pavarde");
     String salis = dane.getString("Salis");
     String adresas=dane.getString("Adresas");
     String telefonas = dane.getString("Telefonas");
     if (imonesPav != null) {imonesPav = imonesPav.trim();
     client.add(imonesPav);}
     if (vardas != null) {vardas = vardas.trim();
     client.add(vardas);}
     if (pavarde != null) {pavarde = pavarde.trim();
     client.add(pavarde);}
     if (salis != null) {salis =salis.trim();
     client.add(salis);}
     if (adresas != null) {adresas =adresas.trim();
     client.add(adresas);}
     if (telefonas != null) {telefonas = telefonas.trim();
     client.add(telefonas);}
    }zadanie.close();
    }catch(SQLException e){}
    return clientVector;    
    }
    }
    public JScrollPane getScrollPane() {
        return scrollPane;
    }
}
  • 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-23T19:01:51+00:00Added an answer on May 23, 2026 at 7:01 pm

    There are a few issues:

    1) You are not adding the client objects to the clientVector. Use clientVector.add(client) to add the client after each iteration of the ResultSet.

    2) You have initialised the table with null data and header variables. First, initialise the data and header variables and then the table, like this:

    private final JTable table ;
    
    public test() {
        super();
        setBounds(100, 100, 781, 412);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        header=new Vector<String>();
        header.add("Imones pavadinimas");
        header.add("vardas");
        header.add("pavarde");
        header.add("salis");
        header.add("Adresas");
        header.add("telefonas");
    
        GtFromDb db=new GtFromDb();
        try {
            data=db.getClient();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
        table = new JTable(data,header);    
    
        try {
            jbInit();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    

    3) You are catching a SQLException and doing nothing with it. So if there is an error running the query, you will not know about it. Try printing out the stack trace:

    try{
       ...
       dane = zadanie.executeQuery();
    }catch(SQLException e) {
       e.printStackTrace();
    } finally {
       zadanie.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

there's a CMS system and there's aspx page without backend file. I can add
There doesn't seem to be any tried and true set of best practices to
There is a field in my company's Contacts table. In that table, there is
There are numerous libraries providing Linq capabilities to C# code interacting with a MySql
There is one table T ( id integer, primary key ( id). I want
There is something I am missing. Say I have the following code: private Bitmap
There is any syntax to use something like this?: <?php function get_foo() { return
There is a strange bug which I can't solve. The bug is reproducable by
There is no problem to get the src or alt separately,but how can get
There is something I miss with the notion of Synchronizing code in Android. Scenario

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.