1. <small id='LY97b'></small><noframes id='LY97b'>

  2. <legend id='LY97b'><style id='LY97b'><dir id='LY97b'><q id='LY97b'></q></dir></style></legend>
    <i id='LY97b'><tr id='LY97b'><dt id='LY97b'><q id='LY97b'><span id='LY97b'><b id='LY97b'><form id='LY97b'><ins id='LY97b'></ins><ul id='LY97b'></ul><sub id='LY97b'></sub></form><legend id='LY97b'></legend><bdo id='LY97b'><pre id='LY97b'><center id='LY97b'></center></pre></bdo></b><th id='LY97b'></th></span></q></dt></tr></i><div id='LY97b'><tfoot id='LY97b'></tfoot><dl id='LY97b'><fieldset id='LY97b'></fieldset></dl></div>

    <tfoot id='LY97b'></tfoot>

      • <bdo id='LY97b'></bdo><ul id='LY97b'></ul>

      如何使用 jdbc 中的 ResultSet.getBinaryStream() 从所有列

      时间:2023-09-30
    1. <legend id='obzwH'><style id='obzwH'><dir id='obzwH'><q id='obzwH'></q></dir></style></legend>

      • <i id='obzwH'><tr id='obzwH'><dt id='obzwH'><q id='obzwH'><span id='obzwH'><b id='obzwH'><form id='obzwH'><ins id='obzwH'></ins><ul id='obzwH'></ul><sub id='obzwH'></sub></form><legend id='obzwH'></legend><bdo id='obzwH'><pre id='obzwH'><center id='obzwH'></center></pre></bdo></b><th id='obzwH'></th></span></q></dt></tr></i><div id='obzwH'><tfoot id='obzwH'></tfoot><dl id='obzwH'><fieldset id='obzwH'></fieldset></dl></div>
          <tbody id='obzwH'></tbody>

        1. <tfoot id='obzwH'></tfoot>
              <bdo id='obzwH'></bdo><ul id='obzwH'></ul>

                <small id='obzwH'></small><noframes id='obzwH'>

                本文介绍了如何使用 jdbc 中的 ResultSet.getBinaryStream() 从所有列中获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                如何使用 jdbc 将整个表写入平面文件(文本文件)?到目前为止,我尝试了以下方法:

                How do I to write an entire table to a flat file (text file) using jdbc? So far I've attempted the following:

                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();
                

                ???"只是我的占位符.我被困在作为参数传递的内容上.

                "????" is just my placeholder. I am stuck on what to pass in as an argument.

                推荐答案

                您可以使用下面的代码从表中获取所有列名和整个数据.writeToFile 方法将包含写入文件的逻辑(如果这还不够明显:))

                You can get all the column names and the entire data from your table using the code below. writeToFile method will contain the logic to writing to file (if that was not obvious enough :) )

                    ResultSetMetaData metadata = rs.getMetaData();
                    int columnCount = metadata.getColumnCount();    
                    for (int i = 1; i <= columnCount; i++) {
                        writeToFile(metadata.getColumnName(i) + ", ");      
                    }
                    System.out.println();
                    while (rs.next()) {
                        String row = "";
                        for (int i = 1; i <= columnCount; i++) {
                            row += rs.getString(i) + ", ";          
                        }
                        System.out.println();
                        writeToFile(row);
                
                    }
                

                这篇关于如何使用 jdbc 中的 ResultSet.getBinaryStream() 从所有列中获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用JAVA中的geotools从定义距离(km)内的线(GPS坐标 下一篇:SQLSTATE 24000 - 游标状态无效

                相关文章

                最新文章

                  1. <tfoot id='0gemn'></tfoot>
                  2. <legend id='0gemn'><style id='0gemn'><dir id='0gemn'><q id='0gemn'></q></dir></style></legend>
                    <i id='0gemn'><tr id='0gemn'><dt id='0gemn'><q id='0gemn'><span id='0gemn'><b id='0gemn'><form id='0gemn'><ins id='0gemn'></ins><ul id='0gemn'></ul><sub id='0gemn'></sub></form><legend id='0gemn'></legend><bdo id='0gemn'><pre id='0gemn'><center id='0gemn'></center></pre></bdo></b><th id='0gemn'></th></span></q></dt></tr></i><div id='0gemn'><tfoot id='0gemn'></tfoot><dl id='0gemn'><fieldset id='0gemn'></fieldset></dl></div>

                    <small id='0gemn'></small><noframes id='0gemn'>

                    • <bdo id='0gemn'></bdo><ul id='0gemn'></ul>