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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:12:36+00:00 2026-06-15T19:12:36+00:00

The First while loop iterates through only one record and then the other while

  • 0

The First while loop iterates through only one record and then the other while loop get iterates through multiple records but first while loop is not getting reference to second record or further. Im using two different resultset object and single statement object am i doing anything wrong pls revert and thanks in advance.

   public void generateCsvFile()
   {
       String vSQL = "";
       String mSQL = "";
       String mDealer_id = "";
        try
        {
            //mSQL = "mSQL"
            mSQL = "select distinct em_controller_id as dealer_id from entity_master";
            System.out.println("mSQL :: \n"+mSQL);
            rs1 = stmt.executeQuery(mSQL);

            while(rs1.next())
            {           

                //System.out.println("@#@# Dealer id @##@#::"+rs1.getString("dealer_id"));
                mDealer_id = rs1.getString("dealer_id");
                vSQL = "select e.em_entity_id,e.em_name,e.em_address_line_1,e.em_address_line_2,e.em_address_line_3,e.em_phone_no_1,e.em_phone_no_2,e.em_dob,e.em_pan_no,e.em_exch_client_id from entity_master e where e.em_controller_id='"+mDealer_id+"'";   
                System.out.println("vSQL :: \n"+vSQL);
                rs = stmt.executeQuery(vSQL);

                FileWriter writer = new FileWriter(mDealer_id+".csv");

                while(rs.next())
                {

                    System.out.println("em_entity_id !@!@!('"+mDealer_id+"') :: "+rs.getString("em_entity_id"));
                    System.out.println("ENTITY :: "+rs.getString("em_entity_id"));
                    writer.append(rs.getString("em_entity_id"));
                    writer.append(',');
                    writer.append(rs.getString("em_name"));
                    writer.append(',');
                    writer.append(rs.getString("em_address_line_1"));
                    writer.append(',');
                    writer.append(rs.getString("em_address_line_2"));
                    writer.append(',');
                    writer.append(rs.getString("em_address_line_3"));
                    writer.append(',');
                    writer.append(rs.getString("em_phone_no_1"));
                    writer.append(',');
                    writer.append(rs.getString("em_phone_no_2"));
                    writer.append(',');
                    writer.append(rs.getString("em_dob"));
                    writer.append(',');
                    writer.append(rs.getString("em_pan_no"));
                    writer.append(',');
                    writer.append(rs.getString("em_exch_client_id"));
                    writer.append('\n');
                }
                rs.close();
//              //generate whatever data you want
                writer.flush();
                writer.close();

            }
            rs1.close();

        }
        catch(Exception e)
        {
             e.printStackTrace();
        }
    }
  • 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-15T19:12:37+00:00Added an answer on June 15, 2026 at 7:12 pm

    I suspect this is the problem:

    rs1 = stmt.executeQuery(mSQL);
    // later...
    rs = stmt.executeQuery(vSQL);
    

    It looks like you’re using the same Statement for two concurrent queries. I’m not really surprised that that’s failed. Use two separate Statement variables – ideally, ones declared within your method. Also:

    • You should also close everything within finally blocks, so that you still close them even if an exception is thrown.
    • You should use parameterized SQL rather than code like this:

      where e.em_controller_id='"+mDealer_id+"'"
      
    • You should use a join rather than executing N+1 queries
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The first time this loop iterates works well but after I press the char
In C# Winforms, while user first load the form, I get the input as
I can only assume this is a bug. The first assert passes while the
When I run the following php code the while loop only runs once even
I came across Side-by-side Assemblies for the first time today while trying to install
I'm having a problem with scala generics. While the first function I defined here
First of all I am getting memory leak while scrolling tableview out of bounds.
While using Aptana and Eclipse for the first time in my programming life for
MOV is probably the first instruction everyone learns while learning ASM. Just now I
First of all: I'm at Scala 2.8 I have a slight issue while using

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.