• Post Reply Bookmark Topic Watch Topic
  • New Topic

new FileWriter("path of the file").write("text")  RSS feed

 
chandrasekharareddy palugulla
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have written a text to a file like

FileWriter writting = new FileWriter("C:/flatFileForBankProduct.txt");
BufferedWriter bw = new BufferedWriter(writting);
ResultSet rs=Statement.executeQuery("select empname,empno from emp");
ResultSetMetaData rsmd=rs.getMetaData();
while(rs.next()){
String empname=rs.getString(1);
String empno=rs.getString(2);
String empdetails=empname+empno+"\n";
bw.write(empdetails);
}

when i excute above code first line is not printing next lines is printing
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure. I suspect your call to rs.next() is discarding the first line. Have look in the ResultSet API documentation, and consider a different type of loop.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!