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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:49:32+00:00 2026-06-10T17:49:32+00:00

I have a problem regarding my JTable, I don’t know how can I store

  • 0

I have a problem regarding my JTable, I don’t know how can I store my fetch records which is of type String from my database to the multidimensional array which is let’s say Object[][] data. What I want to do is show my database records to the JTable, I already fetch the records in dtabase and store it in my String variables, The question is how can I store the fetch records to the multidimensional array of Object and use it on my JTable.

Here are my code for fetching records:

static class TableData{
    Object[][] data;
    int count = 0;
    Statement sql = null;
    String query, user = "JEROME", pass = "Perbert101", driver = "oracle.jdbc.OracleDriver", conString = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
    Connection con = null;
    ResultSet rs = null;
    TableData(){
        try{
            Class.forName(driver);
        }
        catch(ClassNotFoundException e){
            JOptionPane.showMessageDialog(null, "Problem Loading Driver");
        }
        try{
            con = DriverManager.getConnection(conString, user, pass);
            sql = con.createStatement();
            sql.executeQuery("SELECT * FROM INVENTORY");
            rs = sql.getResultSet();
            int key = 0;
            String val = null, val1 = null, val2 = null, val3 = null, val4 = null, val5 = null;
            System.out.println("Results: ");
            while(rs.next()){


                    key = rs.getInt(1);
                    if(rs.wasNull()){
                        key = -1;
                    }
                    val = rs.getString(2);
                    if(rs.wasNull()){
                        val = null;
                    }
                    val1 = rs.getString(3);
                    if(rs.wasNull()){
                        val = null;
                    }
                    val2 = rs.getString(4);
                    if(rs.wasNull()){
                        val = null;
                    }

                    val3 = rs.getString(5);
                    if(rs.wasNull()){
                        val = null;
                    }
                    val4 = rs.getString(6);
                    if(rs.wasNull()){
                        val = null;
                    }
                    val5 = rs.getString(7);
                    if(rs.wasNull()){
                        val = null;
                    }

                System.out.println("Key = " + key);
                System.out.println("value = " + val);
                System.out.println("value = " + val1);
                System.out.println("value = " + val2);
                System.out.println("value = " + val3);
                System.out.println("value = " + val4);
                System.out.println("value = " + val5);

            }


            sql.close();
            con.close();
        }
        catch(SQLException e){
            JOptionPane.showMessageDialog(null, "Error Loading Database Data");
        }

    }
}
//----------END------------
public static void main(String[] args){
    POSModel.TableData data = new POSModel.TableData();
}
  • 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-10T17:49:34+00:00Added an answer on June 10, 2026 at 5:49 pm

    I’d suggest that the data you’re pulling from the database needs to be stored in an array (by columns) first…

    Object[] rowData = new Object[7];
    rowData[0] = key;
    rowData[1] = val;
    rowData[2] = val1;
    rowData[3] = val2;
    rowData[4] = val3;
    rowData[5] = val4;
    rowData[6] = val5;
    

    This then needs to be stored in some kind of row structure, I’d personally use a List. The main reason for this choice is that you probably don’t know in advance the number of rows you will be reading…

    List<Object[]> rowList = new ArrayList<Object[]>(25);
    
    // Process the resultset...
    // Create the column array from above...
    
    rowList.add(rowData);
    

    Once you’ve completed reading all the rows, you need to convert the list it an array…

    data = rowList.toArray(new Object[](rowList.size())); // I like to provide my own array
    

    Equally, you could do…

    data = new Object[rowList.size()][7];
    rowList.toArray(data);
    

    Which ever is more convenient…

    Now you should have a 2D array…

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

Sidebar

Related Questions

I have a problem regarding a JSON string grabbed from WordPress custom post meta.
I have a problem regarding the datediff MYSQL function, I can use it and
I have a problem regarding the name resolution of a type called Action. While
i have a problem regarding the responseXML of ajax.. I have this code from
I seem to have stumbled over a problem regarding saving an xml file from
I have problem regarding date in LINQ query which is binded to a gridview.
I have this problem regarding sql which i will be using in a webservice
I have one problem regarding retriving data from database. I have created one database
I have a problem regarding android database.I have an app which have it's database
I have problem regarding passing the string array as extra in the bundle. 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.