import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class JDBCUtil2 {
//24小时导出一次数据
public static final long PERIOD=24*60*60*1000;
public static final SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//excel行的最大值
public static final double maxRow=10000;
public static int totalData=0;
//设置一个定时器
/*
//public static void setTimer(){
public static void main(String[] args) {
try {
new Timer().scheduleAtFixedRate(new TimerTask() {
public void run() {
exportData();
}
//},sdf.parse("2017-11-23 10:56:50"), 10000);
//每天24点导出一次数据
},sdf.parse("2017-11-23 00:00:00"), PERIOD);
} catch (ParseException e) {
e.printStackTrace();
}
}
*/
public static void main(String[] args) {
//public static void exportData() {
new Thread(new Runnable() {
public void run() {
while(true) {
System.out.println("当前时间:"+sdf.format(new Date()));
try {
Thread.sleep(10000l);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
//读取数据库总数据量,赋值给静态变量,避免频繁读取数据库
getTotal();
long l1=System
java实现从数据库读取数据写入excel,写入多个sheet,6万数据耗时100秒附近
最新推荐文章于 2024-07-24 09:54:02 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)