java - How do you get values from all columns using ResultSet.getBinaryStream() in jdbc? -


How do I write an entire table in a flat file using jdbc? So far, I have made the following efforts:

  statement statement = connection.createStatement (); Result result = statement.executeQuery ("select * FROM tablename"); Buffer input buffer buffer; FileOutputStream Out = New FileOutputStream ("flatfile.txt"); While (result.next ()) {buffer = new BufferedInputStream (result.getBinaryStream ("????")); Byte [] buf = new byte [4 * 1024]; // 4K buffer int lane; While ((lane = buffer reed (buff, 0, buff.lamp)) = -1) {out.write (buf, 0, len); }} Out.close ();   

"????" Only my placeholders are what I pass as an argument, I got stuck about this.

All the data in your table using all the column names and the code given below. WriteToFile method would have reason to write the file (if it was not quite clear :))

  ResultSetMetaData metadata = rs.getMetaData (); Int columncount = metadata.get columncount (); (Int i = 1; i & lt; = columnCount; i ++) {writeToFile (metadata.get columnname (I) + ","); } System.out.println (); While (rsnext ()) {string line = ""; (Int i = 1; i & lt; = columnCount; i ++) for {row + = rs.getString (i) + ","; } System.out.println (); WriteToFile (line); }    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -