java - Hibernate - Exporting data into csv file using file writing -


i trying export data hibernate (using select statement in hql) text file. using simple file writing mechanism write output text file. while writing data text file, junk values getting inserted in syso values displayed properly. may small trivial error stuck in long time.

any appreciated.

i attaching code

public class logic { @suppresswarnings({ "rawtypes", "deprecation" }) public static void main(string[] args) throws ioexception {      configuration cfg = new configuration();     cfg.configure("hibernate.cfg.xml");      sessionfactory factory = cfg.buildsessionfactory();     session session = factory.opensession();     file file = new file("d:/users/output.txt");       filewriter fw = new filewriter(file);     bufferedwriter bw = new bufferedwriter(fw);       query qry = session.createquery("select employee_details a");     list l =(list) qry.list();     system.out.println("total number of records : "+((java.util.list) l).size());     iterator = ((java.util.list) l).iterator();      while(it.hasnext())     {         object o = (object)it.next();         employee_details e = (employee_details)o;         system.out.println("employee id : "+e.getid());         system.out.println("employee name : "+e.getname());         system.out.println("employee salary : "+ e.getsalary());         system.out.println("----------------------");         bw.write(e.getid()); // here instead of id junk value getting inserted      }      bw.flush();     bw.close();      } } 

// other hibernate code here printwriter writer = new printwriter(new bufferedwriter(new filewriter("d:/users/output.txt")));  system.out.println("total number of records : "+((java.util.list) l).size()); iterator = ((java.util.list) l).iterator();     while(it.hasnext())    {         writer.println(e.getid());    }   writer.close(); // put in block 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -