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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:07:38+00:00 2026-05-29T07:07:38+00:00

i am trying to retrieve data from a database and display then on a

  • 0

i am trying to retrieve data from a database and display then on a table in java. Below is the code sample, can someone tell me whats wrong wiz it because when an running it i am getting the following error:
java.lang.NullPointerException.

package sample;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import net.proteanit.sql.DbUtils;

public class Table extends JFrame{
    JTable table;
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

    private void UpdateJTable(){
    String sql = "select firstname, status from tblmember";

    try{
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        table.setModel(DbUtils.resultSetToTableModel(rs));
    }
    catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
    }
    }
    private void conect(){
        conn = myconnection.ConnectDb();        
}

    public Table(){
        setLayout(new FlowLayout());

        String [] columnName={"Name", "Status"};

        Object [][] data={
            {null, null},
            {null, null}
        };

        table = new JTable(data, columnName);
        table.setPreferredScrollableViewportSize(new Dimension(500,50));
        table.setFillsViewportHeight(true);

        JScrollPane sp = new JScrollPane(table);
        add(sp);
    }


    public static void main(String[] args){
        Table gui = new Table();
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setSize(700, 500);
        gui.setVisible(true);
        gui.setTitle("AAAAAAAA");
        gui.UpdateJTable();
        gui.conect();
    }
}
  • 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-29T07:07:39+00:00Added an answer on May 29, 2026 at 7:07 am

    Try inverting the order of these two lines:

    gui.UpdateJTable();
    gui.conect();
    

    to

    gui.conect();
    gui.UpdateJTable();
    

    conn is null when you try and update.

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

Sidebar

Related Questions

I am trying to retrieve data from mysql then display it on android listview.
//hi i am trying to retrieve the data from database and display in my
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm trying to retrieve hierarchical data from a table but am failing to do
I am trying to fetch data from my database and when I display it
Hi i am trying to retrieve data from mysql database to create flot graph
I am trying to retrieve results from a SQlite table, and then assign them
I've been having problems trying to retrieve data from my database to a DataTable
I am trying to retrieve some data from a database using jQuery's $.getJSON method
I am basically trying to retrieve some data from a MySql server, and display

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.