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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:33:20+00:00 2026-05-14T21:33:20+00:00

I have a Java project where I am to connect to a database and

  • 0

I have a Java project where I am to connect to a database and create buttons (next, new, save, delete, previous) to navigate through the database content where there are appropriate text fields and labels for the specific information.

I’ll use the code below as an example (each button is set up very similar)… I have it as follows:

JButton jbtnNext = new JButton("Next ->");
jbtnNext.addActionListener(this);
if (e.getSource() == jbtnNext) jbtnNext_Click();
private void jbtnNext_Click() {
    JOptionPane.showMessageDialog(null, "Next" ,"Button Pressed", 
        JOptionPane.INFORMATION_MESSAGE);

    try {
        if (rset.next()) {
            fillTextFields(true);
        }else{
            //Display result in a dialog box
            JOptionPane.showMessageDialog(null, "Not found");
    }
}
    catch (SQLException ex) {
        ex.printStackTrace();
    }

}

The professor gave the following outline of logic to construct the fillTextFields() method:

  1. Construct the method to provide reusable code that would fill the JTextFields on the GUI with appropriate values from current record from the database (when “Previous or “Next” buttons are pressed) or blank values (when the new Button is pressed).

  2. To determine when the current record was to provide values (next and previous) or the value would be blank (new button) pass a boolean argument into the method. If data from the current record was to be used as fill values, pass true for both previous and next button code after moving the record pointer. If the new button was pressed and want to fill with blank values, pass false to the method.

  3. Inside the method, use a conditional expression to evaluate the boolean variable. If true, The appropriate get—-() resultset method is used to fill the JTextFields. If false, fill them with “”.

  4. The .setText() method of the JTextField is used to fill each JTextField.

  5. Make sure the fillTextFields method throws the appropriate exception.

I understand and have the previous and next button methods passing true, while the new button method is passing false, but I don’t quite understand how to set up the fillTextFields() method correctly or how to “throw the appropriate exception”… Any help would really be appreciated, thank you!

  • 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-14T21:33:21+00:00Added an answer on May 14, 2026 at 9:33 pm

    The fillTextFields method, should, as the name suggest, fills textfields with data you get from the database. I presume that the rset is a global variable, so you should be able to access it from other methods within the same class.

    You can check out this tutorial so that you can get an idea of how to use the textfields in Java.

    In the fillTextFields method, you first check if the boolean that has been passed is true or false, if it is true, you extract the data from the result set and use the .setText(textToPrint) to show the data you have retrieved from the database.

    To retrieve data, you can do as follows:

    rset.getString(1)
    

    The above returns the value stored in the 1st column of the database as a String. You can read through the JavaDoc to see how to return different types.

    With regards to the exception to be thrown, you can check the link to the JavaDoc provided to see which methods throw what exceptions.

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

Sidebar

Ask A Question

Stats

  • Questions 413k
  • Answers 413k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should be able to use a table-valued function. May 15, 2026 at 8:18 am
  • Editorial Team
    Editorial Team added an answer I'm exploring PLINQO 5.0 and here are my answers, 1)… May 15, 2026 at 8:18 am
  • Editorial Team
    Editorial Team added an answer Personally, I would skip the "middle". If the database is… May 15, 2026 at 8:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.