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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:34:13+00:00 2026-05-14T06:34:13+00:00

SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Customer_

  • 0
   SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyy_HHmmSS");
   String strCurrDate = formatter.format(new java.util.Date());
   String strfileNm = "Customer_" + strCurrDate + ".txt";
   String strFileGenLoc = strFileLocation + "/" + strfileNm;
   String Query1="select '0'||to_char(sysdate,'YYYYMMDD')||'123456789' class_code from   dual";
   String Query2="select '0'||to_char(sysdate,'YYYYMMDD')||'123456789' class_code from   dual";
   String Query3="select param from dual"; 
  try {
  Statement stmt = null;
  ResultSet rs = null;
  Statement stmt1 = null;
  ResultSet rs1 = null;

     stmt = conn.createStatement();
     stmt1 = conn.createStatement();
     stmt2 = conn.createStatement();
     rs = stmt.executeQuery(Query1);
     rs1 = stmt1.executeQuery(Query2);
     rs2 = stmt2.executeQuery(Query3);

 File f = new File(strFileGenLoc);
 OutputStream os = (OutputStream)new FileOutputStream(f,true);
 String encoding = "UTF8";
 OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
 BufferedWriter bw = new BufferedWriter(osw);

 while (rs.next() ) {

     bw.write(rs.getString(1)==null? "":rs.getString(1));
     bw.write("  ");


 }
 bw.flush();
 bw.close();
 } catch (Exception e) {
 System.out.println(
     "Exception occured while getting resultset by the query");
 e.printStackTrace();
} finally {
 try {
     if (conn != null) {
         System.out.println("Closing the connection" + conn);
         conn.close();
     }
 } catch (SQLException e) {
     System.out.println(
         "Exception occured while closing the connection");
     e.printStackTrace();
   }
 }
     return objArrayListValue;
}

    The above code is working fine. it writes the content of "rs" resultset data in  text file

   Now what i want is ,i need to append the 


   the content in "rs2" resultset to the "same text file"(ie . i need to append "rs2"  content with "rs" content in the same text file)..

   ------------------edit part----------------

     stmt = conn.createStatement();
     stmt1 = conn.createStatement();
     stmt2 = conn.createStatement();
     rs = stmt.executeQuery(Query1);
     rs1 = stmt1.executeQuery(Query2);
     rs2 = stmt2.executeQuery(Query3);


     while ( rs.next() ) {

     while(rs1.next()){

          while(rs2.next()){

     bw.write(rs.getString(1)==null? "":rs.getString(1));
         bw.write("\t");
     bw.write(rs1.getString(1)==null? "":rs1.getString(1));
     bw.write("\t");
     bw.write(rs2.getString(1)==null? "":rs2.getString(1));
     bw.write("\t");

     bw.newLine();

          }
     }
 }

Above code working fine.
My problem is

  1. “rs” resultset contains one record in the table
  2. “rs1” resultset contains 5 record in the table
  3. “rs2” resultset contains 5 record in the table

“rs” data is getting recursive.

while writing to the same text file , the output i am getting like

1   2    3
1   12   21
1   23   25
1   10   5
1   8    54

but i need output like below

1   2    3
   12   21
   23   25
   10   5
    8    54

What things i need to change in my code.. Please advice

    -----------------edit part1------------------


      Expected Result is 

            1   2    3
            1   12   21
            1   23   25
            1   10   5
            1   8    54

   but output i got like

            1   2    3
            12   21
            23   25
            10   5
             8    54
  • 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-14T06:34:14+00:00Added an answer on May 14, 2026 at 6:34 am
    new FileOutputStream(f,true);
    

    You have already set the append flag to true(the second argument), so do the same as what you did with the previous result set.

    See: http://java.sun.com/javase/6/docs/api/java/io/FileOutputStream.html

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

Sidebar

Related Questions

SimpleDateFormat formatter = new SimpleDateFormat(ddMMyyyy_HHmmSS); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = Cust_Advice_
I used SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm"); String time = formatter.format(new Date()); to
String str = 13/06/2011; SimpleDateFormat formatter = new SimpleDateFormat(dd/MM/yyyy); Date date = (Date)formatter.parse(str);
I am trying to convert a string to proper date format using Java's SimpleDateFormat
I've got the next java code: SimpleDateFormat formatter = new SimpleDateFormat(kk:mm); Date rangoInicio =
I've got a question about SimpleDateFormat class and the java.util.Date's compareto method: I'm constructing
I'm using java.text.SimpleDateFormat to parse string representations of date/time values inside an XML document.
I have the following Java: DateFormat formatter = new SimpleDateFormat( EEE MMM dd yyyy
I am using this code to parse a Date. SimpleDateFormat formatter = new SimpleDateFormat(MM/dd/yyyy);
I've a date = 2011-04-17T22:02:00.001-07:00 that I'm parsing using SDF SimpleDateFormat formatter = new

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.