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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:21:31+00:00 2026-05-20T12:21:31+00:00

I need help on how to scroll back to the next record on the

  • 0

I need help on how to scroll back to the next record on the resultset returned by java. I’m using mysql database.

Here is the code inside the formshow event. Where I load the first resultset that is being returned:

if (rs.next()) {
                jLabel5.setText(rs.getString("Question"));
                jRadioButton1.setText("A. " + rs.getString("A"));
                jRadioButton2.setText("B. " + rs.getString("B"));
                jRadioButton3.setText("C. " + rs.getString("C"));
                jRadioButton4.setText("D. " + rs.getString("D"));

             }

And here’s the button which is supposed to be used to scroll forward through the database.
I need to execute rs.beforeFirst because the things that are displayed on the jFrame doesn’t match with the variable that I’m trying to validate:

   try {




            rs.beforeFirst();

            if (rs.next()) {


                jLabel5.setText(rs.getString("Question"));
                jRadioButton1.setText("A. " + rs.getString("A"));
                jRadioButton2.setText("B. " + rs.getString("B"));
                jRadioButton3.setText("C. " + rs.getString("C"));
                jRadioButton4.setText("D. " + rs.getString("D"));





    if (jRadioButton1.isSelected()) {

                        rval = jRadioButton1.getText().charAt(0);
                        if (String.valueOf(rval).equalsIgnoreCase(rs.getString("Answer"))) {
                           JOptionPane.showMessageDialog(null, "Correct! Your answer is " +  rval + " answer is: " + rs.getString("Answer"));


                        } else {
                           JOptionPane.showMessageDialog(null, "Wrong! your answer is " + rval + " answer is: " +  rs.getString("Answer"));
                        }

                }

                }

            }catch (Exception e) {
            e.printStackTrace();
        }

My question is how do I continue on scrolling through the database. Because the resultset doesn’t progress when I use the rs.beforeFirst() before the rs.next()
I also tried doing:

while(rs.next()){...}

It worked but it didn’t let me choose what radioButton I want. And it continued to execute until the end of the result set even without manually clicking on the button(for scrolling) multiple times. Please help me figure out what’s the solution to this. If you need more details just ask. 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-20T12:21:32+00:00Added an answer on May 20, 2026 at 12:21 pm

    You shouldn’t be mingling database access logic with presentation logic. That only leads to tight coupled code where the both concerns only collides with each other. The database job needs to be done as soon as possible.

    You need to separate the concerns.

    First create a class which represents a single row of the database.

    public class Question {
        private String text;
        private String answer;
        private String optionA;
        private String optionB;
        private String optionC;
        private String optionD;
    
        // Add/generate c'tors/getters/setters/equals/hashcode and other boilerplate.
    }
    

    (a bit decent IDE like Eclipse can autogenerate them)

    Then create a class which does the following JDBC job:

    public List<Question> list() throws SQLException {
        List<Question> questions = new ArrayList<Question>();
        // ...
    
        try {
            // ...
    
            while (resultSet.next()) {
                Question question = new Question();
                question.setText(resultSet.getString("Question"));
                question.setAnswer(resultSet.getString("Answer"));
                question.setOptionA(resultSet.getString("A"));
                question.setOptionB(resultSet.getString("B"));
                question.setOptionC(resultSet.getString("C"));
                question.setOptionD(resultSet.getString("D"));
                questions.add(question);
            }
        } finally {
            // ...
        }        
    
        return questions;
    }
    

    Finally just work with List<Question> the straightforward way.

    List<Question> questions = questionDAO.list();
    int size = questions.size();
    JOptionPane.showMessageDialog(null, "There are " + size + " questions!");
    
    for (Question question : questions) {
        jLabel5.setText(question.getText());
        jRadioButton1.setText("A. " + question.getOptionA());
        jRadioButton2.setText("B. " + question.getOptionB());
        jRadioButton3.setText("C. " + question.getOptionC());
        jRadioButton4.setText("D. " + question.getOptionD());
        // ...
    }
    

    No need to massage the resultset forth and back.

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

Sidebar

Related Questions

need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
Need help writing a script downloads data from google insight using c# this is
need help in error in database pivot. i have table tamed table_score like below:
I need some help adjusting the logic of my jquery function. Here's how the
I need help on placing images(back and forward images) at two ends of my
I need help with aucomplete of the jquery. jQuery(#PeopleName).autocomplete( {source:[name1,name2,...], minLength:2, max:10, scroll:true}); The
Trying to use JQuery to scroll through a ul li list using class next
I am using the Cakephp framework and I need help changing the text color
Here's the problem : I need to scroll a huge image of a wave
I'm new to using jquery and need help. I'm using the scrolltofixed.js and need

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.