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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:31:14+00:00 2026-05-27T10:31:14+00:00

I am working on a java project I am using jdk 1.6 I am

  • 0

I am working on a java project
I am using jdk 1.6

I am want to add data from database in jtable
I have achieved this by using DefaulTableModel
and I got the column names by using ResultSetMetadata
but the problem is

**I am getting a extra column name A at the 0th index of jtable
I want to remove this column
it looks like this

A | deptno

I only need deptno
**

the code used for creating this model is

private void updateTable() throws Exception {

    String sqlrow = "Select count(*) from emp";
    rs= db.sta.executeQuery(sqlrow); 
        rs.next();                           
     int rows=rs.getInt(1);  
    System.out.println(""+rows);


    String sqldata = "SELECT deptno FROM emp";
   rs =db.sta.executeQuery(sqldata);
    rsMD = rs.getMetaData();
   numberOfColumns = rsMD.getColumnCount();
   ColumnNames = new String[numberOfColumns+1];
    System.out.println(""+numberOfColumns);

    for(int i=1;i<=numberOfColumns;i++)
    {
        String colName=rsMD.getColumnName(i);
        ColumnNames[i] = colName;
        System.out.println(""+ColumnNames[i]);
    }


    //Cj is a method which takes sqlQuery , rows, column
    Object[][] rowData=CJ(sqldata,rows,numberOfColumns);
    //jt is table name 
    jt.setModel(new DefaultTableModel(rowData,ColumnNames));

}

// code for cj()

     public Object[][] CJ(String sql,int rows,int cols)
{
    Object[][] obj=new Object[rows][cols+1];
    ResultSet rs=null;
    try{
         rs= db.sta.executeQuery(sql);
        int c=0;
            while(rs.next())
            {        
            for(int i=1;i<=cols;i++)
                {
                      obj[c][i]=rs.getString(i);                        
                }
                c++;
            }

        }
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
    return obj;
}

I am using this code on
button click

                 updateTable();
            jsp = new JScrollPane(jt); // jt is Jtable
             jp.add(jsp); //jp is jpanel

please help me out

  • 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-27T10:31:15+00:00Added an answer on May 27, 2026 at 10:31 am

    Not following the naming convention makes it hard to read, but I would suggest to take a closer look at the following piece of code

       numberOfColumns = rsMD.getColumnCount();
       ColumnNames = new String[numberOfColumns+1];
        System.out.println(""+numberOfColumns);
    
        for(int i=1;i<=numberOfColumns;i++)
        {
            String colName=rsMD.getColumnName(i);
            ColumnNames[i] = colName;
            System.out.println(""+ColumnNames[i]);
        }
    

    Here you explicitly use more column names then numberOfColumns. Idem for your CJ method, where you start at index 1.
    Just start all those for loops at index 0, make the arrays one shorter and everything should work

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

Sidebar

Related Questions

I am working on a Java project using spring2 and Maven. I have already
I'm working on a java project that receives midi events from midi hardware using
I'm working on a project using Java RMI. This is the class causing problem:
I'm working on my first project using Python 2.7. We're coming from a Java
I have a java project in eclipse which are using tomcat. This project has
I am working on a Java project in Eclipse. In this I am using
I am working on a Java project using Netbeans for the first time. I
I am a Java programmer and was working on a project using Hibernate and
I'm working on a compiler design project in Java. Lexical analysis is done (using
I'm working on a project where we're using a Java applet for part of

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.