To write the contents of ResultSet into a file, is there a better way?
-
I want to write the contents of the ResultSet to a CSV file. I have used the following code to for the same: query="select * from client where client name= "+custName; st=con.prepareStatement(query); rs=st.executeQuery(query); System.out.println(query); while(rs.next()) { int colNo=rs.getMetaData().getColumnCount(); //System.out.println("Enter the name of the file:"); //String name=bufIn.readLine(); File f=new File(fname); FileWriter fstream = new FileWriter(f); bufferedWriter = new BufferedWriter(fstream); for(int i=1;i<(colNo+1);i++) { bufferedWriter.append(rs.getMetaData().g… System.out.println(rs.getMetaData().getC… if(i<colNo) { bufferedWriter.append(","); } else { bufferedWriter.append("\r\n"); } } **************************************… I have used buffered writer to write the file as you can see above. Please tell me if using buffered writer the best way to write in a CSV file. I want to use a very efficient IO code, since this code gets deployed on server. Plz help. To write the contents of ResultSet into a file, is there any oter better way?
-
Answer:
use PrintWriter with which you can use print, println methods.
Asghar at Yahoo! Answers Visit the source
Related Q & A:
- How to write binary data to a file?Best solution by Stack Overflow
- Which is better way to experience Hawaii?Best solution by Yahoo! Answers
- Organizing a teen room in a cute way?Best solution by thriftyfun.com
- How is .txt file different from a .dat file in C?Best solution by mycplus.com
- What is the better way to get a part time job?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.