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

The Archive Base Latest Questions

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

i try to insert data from database to Jtable there is my code: private

  • 0

i try to insert data from database to Jtable
there is my code:

private Vector <Vector<String>> data;
private Vector<String> header;
table.setModel(new javax.swing.table.DefaultTableModel(
data,header     
));

GtFromDb db=new GtFromDb();
data=db.getClient();

header=new Vector<String>();
header.add("Imones pavadinimas");
header.add("vardas");
header.add("pavarde");
header.add("salis");
header.add("Adresas");
header.add("telefonas");

public Vector getClient() 
{
    Vector <Vector<String>> clientVector=new Vector<Vector<String>>();  
    try
    {
         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;    
    }

it thorows me error:

java.lang.NullPointerException
at test$GtFromDb.getClient(test.java:108)
at test.<init>(test.java:49)
at test.main(test.java:24)

where is problem?

  • 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:34:34+00:00Added an answer on May 23, 2026 at 7:34 pm

    you forgot to added and another …

    1) client=new Vector<String>(); to the DefaultTableModel inside loop while(dane.next()) {...}

    2) public Vector getClient() must be initialized return null

    3) change public Vector getClient() to public void getClient(), remove return statement

    4) PreparedStatement zadanie must be closed in finally block try- catch - finally

    5) dane = zadanie.executeQuery(); looks like as Resultset, and same as PreparedStatement zadanie must be closed in finally block

    6) JTable and Vector can hold null value

    7) if you are only to want to display data from DbTable to the JTable then look for ResultsetTableModel, TableFromDatabase, you can search for that on this forum too

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

Sidebar

Related Questions

I read a set of data from database first Insert a new record using
I am attempting to insert data into a local SQLITE database file from a
I insert data from a typed dataset into my MSSQL database by using SqlBuldCopy
I use C# web service to insert, delete and get data from MySql database.
I want to insert data in MYSQL database using python here my code import
If I try to insert data with a 20 digit primary key into a
I have problem when I try insert some data to Informix TEXT column via
I have the following table. When i try to insert records using LINQ to
I am trying to add data from a dataset to an access table(.mdb). I
I'm trying to export some data from MATLAB to a database. I use a

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.