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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:21:54+00:00 2026-05-10T21:21:54+00:00

I have problem with return statment >.< I want to store all magazine names

  • 0

I have problem with return statment >.< I want to store all magazine names into

ArrayList<String> ListNameMagazine = new ArrayList<String>(); 

I have a DB; in the DB there is a table name_magazine and the data in name_magazine is

Magazine1

Magazine2

Magazine3

Magazine4

This my main:

    ShowData Show = new ShowData();      int HowManyMagazine = Show.HowManyMagazine(1); // to make sure there is how many Magazine name in my database      //System.out.print(HowManyMagazine); //i want to make sure the data is out.      String nmeMagazine = null; // this variable for get data from return statement       // i want to store in ListNameMagazine     ArrayList<String> ListNameMagazine = new ArrayList<String>();          for (int numbeer = 0;numbeer <= HowManyMagazine ; numbeer++)     {        //Store in 1 variable String, because if arrayList it's error         nmeMagazine = Show.getResult("Select Name_Magazine from Magazine");         // Store again in array list         ListNameMagazine.add(nmeMagazine);     }          for (String s : ListNameMagazine)     {         System.out.println(s); // show the data     } 

This is my return statement:

public String getResult(String sql) throws SQLException {     ResultSet rs = st.executeQuery(sql);     ResultSetMetaData resultsetmetadata = rs.getMetaData();      //String just_try = null;     while (rs.next()) {           System.out.println("Result:"+rs.getString(1));          //just_try = rs.getString(1);          //return just_try;     }     return null;    //return just_try; } 

The problem is in return statement.

When the comment ( // ) I erase and the last return null; I delete. It become like here:

public String getResult(String sql) throws SQLException {               ResultSet rs = st.executeQuery(sql);      ResultSetMetaData resultsetmetadata = rs.getMetaData();      String just_try = null;            while (rs.next()) {           //System.out.println("Result:"+rs.getString(1));         just_try = rs.getString(1);         return just_try;      }       return just_try;  } 

When I show the data using this statement.

for (String s : ListNameMagazine)     {         System.out.println(s); // show the data     } 

the result only

Magazine4

Magazine4

Magazine4

Magazine4

@.@ I have confuse where the miss @.@

but when I show data in return statement like this

public String getResult(String sql) throws SQLException     {              ResultSet rs = st.executeQuery(sql);     ResultSetMetaData resultsetmetadata = rs.getMetaData();     String just_try = null;      while (rs.next()) {              System.out.println("Result:"+rs.getString(1));         //just_try = rs.getString(1);         //return just_try;     }      return null; } 

The data show what I want. I know I only miss in somewhere but I don’t know where that @.@. I hope you guys can found it .THX

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

    Your problem is that return returns only one thing, and it will return immediately and the function will exit! You are retuning the name of a magazine just_try.

    while (rs.next()) {       //System.out.println('Result:'+rs.getString(1));     just_try = rs.getString(1);    return just_try;  } 

    So, you start iterating through rs, and you get the name:

    just_try = rs.getString(1); 

    And then you tell the code to return just_try.

    return just_try; 

    At this point just_try will be returned and the function will exit! I think your problem is that you are expecting the function to keep going, and to keep returning values to the code that calls it, but this is not the way it works.

    I suspect what you want to do is something like this:

    ArrayList<String> ListNameMagazine; ListNameMagazine = Show.getResult('Select Name_Magazine from Magazine'); 

    then in the function getResult:

    public ArrayList<String> getResult(String sql) throws SQLException {      ResultSet rs = st.executeQuery(sql);      ResultSetMetaData resultsetmetadata = rs.getMetaData();      ArrayList<String> returnArrayList = new ArrayList<String>();      while (rs.next()) {           returnArrayList.add(rs.getString(1));      }     return returnArrayList;  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I've been thinking about using formal methods to help clarify… May 11, 2026 at 12:40 pm
  • added an answer Can you handle this through the Visual Studio extensibility framework?… May 11, 2026 at 12:40 pm
  • added an answer Use the QUOTENAME function. May 11, 2026 at 12:40 pm

Related Questions

I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have a problem with a little .Net web application which uses the Amazon
I have a problem with a ClickOnce deployment of a Windows Forms application. When
I have a small code example I want to include in the Javadoc comment
Problem: I have an enumerated type which has description tags in the following style:
I want to convert function object to function. I wrote this code, but it
I seem to have a problem with this SQL query: SELECT * FROM appts

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.