熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

數據庫的轉excel測試

2013-11-23 19:01:17  來源: Java核心技術 

  package dbToxml;
    /**
     * @author Alex
     * @msg 把數據庫轉化為excel
     */
    import javaioFile;
    import javaioIOException;
    import javasqlResultSet;
    import javasqlSQLException;

  import jxlCell;
    import jxlWorkbook;
    import jxlwriteLabel;
    import jxlwriteWritableSheet;
    import jxlwriteWritableWorkbook;
    import jxlwriteWriteException;
    import jxlwritebiffRowsExceededException;

  public class Oracle_to_Excel {
    ResultSet rs=null;
    public void serch(){
         //ConnOracle oracle=new ConnOracle();
         String sql=select * from purchase_info;
         //ResultSet rs=oraclequery(sql);
         WritableWorkbook book=null;
         WritableSheet sheet=null;
         try
         {
         //Excel獲得文件
         Workbook wb=WorkbookgetWorkbook(new File(e:\\測試xls)); //打開一個文件的副本並且指定數據寫回到原文件
         book= WorkbookcreateWorkbook(new File(e:\\測試xls)wb); //添加一個工作表
         sheet=bookcreateSheet(第五頁);
         //sheetaddCell(new Label(第二頁的測試數據));
         //jxlwriteNumber c=new jxlwriteNumber();
         //sheetaddCell(c);
         //bookwrite();
         //bookclose();
         }catch(Exception e)
         {
         Systemoutprintln(e);
         }
         int j=;
         try {
       while(rsnext()){
        int i=;
        sheetaddCell(new jxlwriteNumber(ijrsgetInt()));
        sheetaddCell(new Label(++ijrsgetString(pur_name)));
        sheetaddCell(new Label(++ijrsgetString(pur_address)));
        sheetaddCell(new Label(++ijrsgetString(pur_mail)));
        //String date=rsgetDate(pur_date)toString();
        //sheetaddCell(new Label(i++jdate));
        j++;
       }
      } catch (RowsExceededException e) {
       // TODO Autogenerated catch block
       eprintStackTrace();
      } catch (WriteException e) {
       // TODO Autogenerated catch block
       eprintStackTrace();
      } catch (SQLException e) {
       // TODO Autogenerated catch block
       eprintStackTrace();
      }
         try {
       bookwrite();
       bookclose();
      } catch (WriteException e) {
       // TODO Autogenerated catch block
       eprintStackTrace();
      } catch (IOException e) {
       // TODO Autogenerated catch block
       eprintStackTrace();
      }

  }

  public static void main(String[] args) {
      Oracle_to_Excel oratoex=new Oracle_to_Excel();
      oratoexserch();
     }

  }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26150.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.