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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:27:54+00:00 2026-06-01T11:27:54+00:00

I have tried all the solutions that have been provided including using PRAGMA but

  • 0

I have tried all the solutions that have been provided including using PRAGMA but i can’t seem to get it to work!!! I have a program that allows the user to create a table name it and manually enter column names that they wish. I need to some how obtain the column names from the selected table. I need by “Private void loadDB” function to do this. As you can see i have used a bunch of ways of trying to get it to work however it wont extract the names.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;


public class ViewTable extends JFrame {

    private static final long serialVersionUID = 1L;
    private static final String PREFERRED_LOOK_AND_FEEL = null;
    private final String tableName;
    private String[] columnNames;
    private String[][] data;
    private JTable tablePane;

    public ViewTable(String tableName){
        this.tableName=tableName;

        initComponents();
        loadDB();
        displayTable();

        setDefaultCloseOperation(CreateTemplate.EXIT_ON_CLOSE);
        setSize(700,700);
        setTitle("View Table");
        setVisible(true);


    }

    private void initComponents() {
        JPanel mainPanel = new JPanel(new BorderLayout());
        this.add(mainPanel);
        mainPanel.setBackground(Color.yellow);

        JPanel topPanel = new JPanel(new BorderLayout());
        topPanel.setBackground(Color.blue);
        mainPanel.add(topPanel,BorderLayout.NORTH);

        JLabel titleLabel = new JLabel(this.tableName);
        titleLabel.setBorder(new LineBorder(Color.black));
        titleLabel.setFont(new Font("Helvetica", Font.BOLD, 24));
        titleLabel.setForeground(Color.orange);
        titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
        topPanel.add(titleLabel,BorderLayout.CENTER);

        JButton exitButton = new JButton("Finish");
        exitButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent event){
                close_window();
            }
        });
        exitButton.setBorder(new EmptyBorder(new Insets(20,20,20,20)));
        topPanel.add(exitButton,BorderLayout.EAST);

    }

    private void close_window(){ this.dispose(); }

    private void loadDB(){
        //String com = "SELECT sql from sqlite_master WHERE tbl_name = '"+tableName+"' AND type = 'table'";
        //String com = "PRAGMA table_info( "+tableName+" );";
        //String com = "INSERT null";
        //SQLCommands.SQLCommand(com);
        //String com = "SELECT * FROM sqlite_master";
        //String[] output = SQLCommands.returnSQLCommand(com);
        //String com = "SELECT * FROM (PRAGMA table_info("+tableName+");"; 
        //String[] output = SQLCommands.returnSQLCommand(com);

        //for (String S : output){ System.out.println(S); JOptionPane.showInputDialog("Enter template name"); }


        //get column names
        //columnNames = new String[3];
        //columnNames[0] = "Name"; columnNames[1] = "Surname"; columnNames[2] = "Sex";

        //use column names to populate data
        //e.g. data[4][0] => "SELECT Name FROM tableName"[4]

    }

    private void displayTable(){
        //use JTable

        //new JScrollPane which uses the table

        //put JScrollpane in CENTER box

    }

    public static void main(String[] args){
        String [] tableNames = SQLCommands.returnSQLCommand("SELECT name FROM sqlite_master");
        new ViewTable(tableNames[9]);
    }

}
  • 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-01T11:27:55+00:00Added an answer on June 1, 2026 at 11:27 am
    PRAGMA table_info(table_name);
    

    will do the trick ?

    SQL Lite PRAGMA

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

Sidebar

Related Questions

I know that variations on this question have been asked, but I've tried all
I have tried almost all the solutions from SO but no success :(. I
All right so I tried using the button set. So fair, I have been
I have been trying to use regex but I cant seem to get it
i have tried looking online but had no luck, How i could delete all
How can I replace all line-endings in big file (>100MB)? I have tried to
Have tried to find solutions for this and can't really come up with anything.
I have been putting only jQuery mask so far, but I figured out that
I cannot seem to get the value from a select option that has been
I've tried to search for similar problems, but can't seem to find it. I

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.