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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:12:52+00:00 2026-05-27T05:12:52+00:00

I have writted a Java program that will be able to add customers to

  • 0

I have writted a Java program that will be able to add customers to a database, and then look them up via a username or customer_id.

I am able to add users to the database without issue. Also, I am able to select a user by username or customer_id and print the user information into a JTextArea for viewing. What I would like to do, however, is print the user information from each specific column in their row of the database to the corresponding JTextField on my form. I think I need to use an array to do so, but I have had no success thus far.

The code I have at this point to select data is as follows:

public String selectCustomer() throws ClassNotFoundException, SQLException{
    String result = "";
    String strSQL = "SELECT * FROM customer WHERE username = '" + this.getUsername() + "'"; 
    DataAccess DA = new DataAccess();
    ResultSet rs;
    try{
        rs = DA.getResultSet(strSQL);
        ResultSetMetaData metaData = rs.getMetaData();
        int columns=metaData.getColumnCount();
        while(rs.next()){//reading one record
            for(int i=1;i<=columns;++i) {//this reads column by column
                result+="<"+metaData.getColumnName(i)+">";
                result+=rs.getString(i);
                result+="</"+metaData.getColumnName(i)+">\n";
            }//closes for loop
        }//closes while loop
    }//closes try       
    catch(SQLException sqle){sqle.printStackTrace();}   
    catch(Exception e){e.printStackTrace();}
    return result;
}

Now I need to alter that code to place my column results into an array, and then I should be able to simply pull the data from the array, correct? I could be completely off my rocker here. I don’t know. D:

Any advice would be appreciated.

Thanks!

  • 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-27T05:12:52+00:00Added an answer on May 27, 2026 at 5:12 am

    Sure, you can get the values from the ResultSet using getString (and other getXXX methods) and then use setText to put the values into your text field.

    This tutorial may help: http://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html

    PS I forgot to say, you can get the values by column name rather than column index if you like – this is slightly slower but makes the code easier to write and maintain.

    HTH

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

Sidebar

Related Questions

I have written a java program that is actually works as a gui to
I have a Java program that is mostly GUI and it shows data that
I have a Java program that runs a number of other programs. Once the
On Mac OSX 5.8 I have a Java program that runs at 100% CPU
I have written a nice program in Java that connects to a gmail account
I have a Java program which needs to be a startup program that runs
I have a Java program that I must do for homework, and here's the
I have a program which i have myself written in java, but I want
As a Christmas gift I have written a small program in Java to calculate
I have written a java annotation that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) // can

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.