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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:30:30+00:00 2026-06-08T23:30:30+00:00

in java.How to save a result of a sql query into a variable? java.sql.PreparedStatement

  • 0

in java.How to save a result of a sql query into a variable?

        java.sql.PreparedStatement preparedStatement = null;
        String query = "select season from seasonTable where league_name=?";

        preparedStatement = conn.prepareStatement(query);

        preparedStatement.setString(1, league);
        ResultSet rs = preparedStatement.executeQuery();

I need to save the retrieved season into a variable how can I do this ?

  • 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-08T23:30:32+00:00Added an answer on June 8, 2026 at 11:30 pm

    You can call rs.next() to move the cursor for the ResultSet to the next row. That method will return a boolean indicating whether or not there actually is a next row, so you can use either an if statement or a while loop to retrieve the first or all of the rows returned.

    // only ever retrieve the value from the first returned row, even if there are multiple
    String season = null;
    if(rs.next())
        season = rs.getString(1);
    

    OR

    // retrieve the values of all returned rows and store them in a list
    List<String> seasons = new ArrayList<String>();
    while(rs.next())
        seasons.add(rs.getString(1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use the Java method: Runtime.getRuntime().availableProcessors() and save the result in a
I retrieve XML from a server, save it into an SD card, then parse
I want to take a snapshot with my webcam using java and save it
I'm using java persistence to save a list of entities that are associated to
Possible Duplicate: Create Excel file in Java How to save output in excel format
I want to use java key store to save keys and certificates. can anybody
I am trying to save a file (and then read it later) in java
In a java serialization problem, I want to save some classes name and I
I have written code in Java to access web cam,and to save image... I
Possible Duplicate: Platform independent paths in Java I make a program but it save

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.