java 50万数据实时查询_java从oracle读取50万条数据写入Excel中抛GC overhead limit exc

这段代码演示了如何使用Java从Oracle数据库中查询数据,并将结果批量写入Excel文件。通过建立数据库连接,执行SQL查询,遍历结果集并填充到Excel工作表中,最终保存为'西安计量箱合并.xlsx'文件。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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("导出成功");

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值