姬長信(Redy)

java – 如何使用jdbc中的ResultSet.getBinaryStre…


如何使用jdbc将整个表写入平面文件(文本文件)?到目前为止,我尝试了以下内容:
Statement statement = connection.createStatement();
   ResultSet result = statement.executeQuery("SELECT * FROM tablename");
   BufferedInputStream buffer;
   FileOutputStream out = new FileOutputStream("flatfile.txt");
   while(result.next() )
   {
      buffer =  new BufferedInputStream(result.getBinaryStream("????") );
      byte[] buf = new byte[4 * 1024]; //4K buffer
      int len;
      while( (len = buffer.read(buf, 0, buf.length) ) != -1 )
      {
          out.write(buf, 0, len );
      }
   }
   out.close();

“????”只是我的占位符.我被困在作为论点传递的内容上.