数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

数据库的转excel测试


发布日期:2023年05月24日
 
数据库的转excel测试

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

}

}

               

上一篇:在Java中调用Oracle的过程和函数

下一篇:Java采用相对路径连接access数据库