该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package com.OracleExcel;
import java.sql.*;
import java.io.*;
import java.util.Date;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class OracleExpertExcel {
@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
XSSFWorkbook xssfworkbook=new XSSFWorkbook();
XSSFSheet xssfsheet=xssfworkbook.createSheet("book");
Connection ct=null;
Statement ps=null;
ResultSet rs=null;
String sql="select * from jlx";
int i=0;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
ct=DriverManager.getConnection("jdbc:oracle:thin:@LENOVO-PC:1521:orcl","sjhc","sjhc");
ps=ct.createStatement();
rs=ps.executeQuery(sql);
while(rs.next()){
XSSFRow xssfrow=xssfsheet.createRow(i);
XSSFCell xssfcell0=xssfrow.createCell((short)0);
xssfcell0.setCellValue(rs.getString(1));
XSSFCell XSSFcell1=xssfrow.createCell((short)1);
XSSFcell1.setCellValue(rs.getString(2));
XSSFCell XSSFcell2=xssfrow.createCell((short)2);
XSSFcell2.setCellValue(rs.getString(3));
XSSFCell XSSFcell3=xssfrow.createCell((short)3);
XSSFcell3.setCellValue(rs.getString(4));
XSSFCell XSSFcell4=xssfrow.createCell((short)4);
XSSFcell4.setCellValue(rs.getString(5));
XSSFCell XSSFcell5=xssfrow.createCell((short)5);
XSSFcell5.setCellValue(rs.getString(6));
XSSFCell XSSFcell6=xssfrow.createCell((short)6);
XSSFcell6.setCellValue(rs.getString(7));
XSSFCell XSSFcell7=xssfrow.createCell((short)7);
XSSFcell7.setCellValue(rs.getString(8));
XSSFCell XSSFcell8=xssfrow.createCell((short)8);
XSSFcell8.setCellValue(rs.getString(9));
XSSFCell XSSFcell9=xssfrow.createCell((short)9);
XSSFcell9.setCellValue(rs.getString(10));
XSSFCell XSSFcell10=xssfrow.createCell((short)10);
XSSFcell10.setCellValue(rs.getString(11));
XSSFCell XSSFcell11=xssfrow.createCell((short)11);
XSSFcell11.setCellValue(rs.getString(12));
XSSFCell XSSFcell12=xssfrow.createCell((short)12);
XSSFcell12.setCellValue(rs.getString(13));
XSSFCell XSSFcell13=xssfrow.createCell((short)13);
XSSFcell13.setCellValue(rs.getString(14));
XSSFCell XSSFcell14=xssfrow.createCell((short)14);
XSSFcell14.setCellValue(rs.getString(15));
XSSFCell XSSFcell15=xssfrow.createCell((short)15);
XSSFcell15.setCellValue(rs.getString(16));
XSSFCell XSSFcell16=xssfrow.createCell((short)16);
XSSFcell16.setCellValue(rs.getString(17));
XSSFCell XSSFcell17=xssfrow.createCell((short)17);
XSSFcell17.setCellValue(rs.getString(18));
XSSFCell XSSFcell18=xssfrow.createCell((short)18);
XSSFcell18.setCellValue(rs.getString(19));
XSSFCell XSSFcell19=xssfrow.createCell((short)19);
XSSFcell19.setCellValue(rs.getString(20));
XSSFCell XSSFcell20=xssfrow.createCell((short)20);
XSSFcell20.setCellValue(rs.getString(21));
XSSFCell XSSFcell21=xssfrow.createCell((short)21);
XSSFcell21.setCellValue(rs.getString(22));
XSSFCell XSSFcell22=xssfrow.createCell((short)22);
XSSFcell22.setCellValue(rs.getString(23));
i++;
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
try {
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
if(ct!=null){
ct.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FileOutputStream fileoutputstream=new FileOutputStream("C:/Users/lenovo/Desktop/西安计量箱合并.xlsx");
xssfworkbook.write(fileoutputstream);
fileoutputstream.close();
System.out.println("导出成功");
}
}