「Java批次」java批次查询

博主:adminadmin 2022-11-22 18:57:06 76

今天给各位分享Java批次的知识,其中也会对java批次查询进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java 如何批量插入数据

通过jdbc就可以执行批量插入了。

以下案例:

1、逐条执行10万次

2、分批执行将10万分成m批,每批n条,分多种分批方案来执行。

/**

* 批处理执行

*

* @param m 批次

* @param n 每批数量

* @throws Exception 异常时抛出

*/

public static void testInsertBatch(int m, int n) throws Exception {

init(); //初始化环境

Long start = System.currentTimeMillis();

for (int i = 0; i m; i++) {

//从池中获取连接

Connection conn = myBroker.getConnection();

Statement stmt = conn.createStatement();

for (int k = 0; k n; k++) {

String sql = "\n" +

"insert into testdb.tuser \n" +

"\t(name, \n" +

"\tremark, \n" +

"\tcreatetime, \n" +

"\tupdatetime\n" +

"\t)\n" +

"\tvalues\n" +

"\t('" + RandomToolkit.generateString(12) + "', \n" +

"\t'" + RandomToolkit.generateString(24) + "', \n" +

"\tnow(), \n" +

"\tnow()\n" +

")";

//加入批处理

stmt.addBatch(sql);

}

stmt.executeBatch(); //执行批处理

stmt.close();

myBroker.freeConnection(conn); //连接归池

}

Long end = System.currentTimeMillis();

System.out.println("批量执行" + m + "*" + n + "=" + m * n + "条Insert操作,共耗时:" + (end - start) / 1000f + "秒!");

}

如何用java批次把txt内容写入excel

jxl.jar

这个demo简单,但是只要是写excel,读txt应该这样,由于你的txt有一些=,可以正则表达式

删减即可

java :怎么实现分批次导出excel的条数限制,每次导出的excel压缩成zip,并且导出时给用户添加友好提示?

你这问题太大了

HSSFWorkbook 是导出excel的工具,可是实现导出excel控制条数

//开始打印

HSSFWorkbook wb = new HSSFWorkbook();

HSSFSheet sheet=wb.createSheet("sheet1");

HSSFRow row = sheet.createRow(0);

//设置第一行标题

HSSFCell cell;

JobColumn jobColumn = null;

int colsAddSize = NewmasterstudentAction.COLS4EXPORT_CODE.length;

for(int i=0 ; icolsAddSize ; i++){

cell = row.createCell((short)i);

cell.setCellValue(NewmasterstudentAction.COLS4EXPORT_CODE[i]+"("+NewmasterstudentAction.COLS4EXPORT_NAME[i]+")");

}

for(int i=0;ijobList.size();i++){

UserJobColumn userJob = jobList.get(i);

jobColumn = userJob.getJobColumn();

cell = row.createCell((short)(i+colsAddSize));

cell.setCellValue(jobColumn.getColumnCode()+"("+jobColumn.getColumnName()+")"); //字段代码

}

//打印记录

SetEntryString,ListJobRecord entrySet = des.entrySet();

IteratorEntryString, ListJobRecord it = entrySet.iterator();

int index = 1;

while(it.hasNext()){

EntryString, ListJobRecord en = it.next();

row = sheet.createRow(index++);

String xh = en.getKey();

//打印学生信息

cell = row.createCell((short)0);

cell.setCellValue(xh);

NewMasterStudent stu = studentMap.get(xh);

if(stu != null){

cell = row.createCell((short)1);

cell.setCellValue(stu.getYbd() ? "是" : "否");

cell = row.createCell((short)2);

cell.setCellValue(stu.getRemark() == null ? "" : stu.getRemark());

}

//打印记录

ListJobRecord records = en.getValue();

for(int i=0 ; i jobList.size() ; i++){

cell = row.createCell((short)(i+colsAddSize));

UserJobColumn g = jobList.get(i);

JobRecord record = null;

if(i records.size()){

record = records.get(i);

if(!g.getJobColumn().getId().equals(record.getJobColumn().getId())){

record = new JobRecord();

record.setJobColumn(g.getJobColumn());

records.add(i, record);

}

}else{

record = new JobRecord();

record.setJobColumn(g.getJobColumn());

records.add(i, record);

}

if(Constant.NS_JOBCOLUMN_TYPE_INPUT.equals(record.getJobColumn().getColumnType())){

cell.setCellValue(record.getEditLr());

}else if(Constant.NS_JOBCOLUMN_TYPE_SELECT.equals(record.getJobColumn().getColumnType())){

cell.setCellValue(record.isEditState() ? "是":"否");

}else if(Constant.NS_JOBCOLUMN_TYPE_OPTION.equals(record.getJobColumn().getColumnType())){

SyGeneralCode select = record.getSelectedValue();

if(select != null){

cell.setCellValue(select.getCode()+" | "+select.getCnName());

}

}

}

}

ZipEntry 可以实现导出zip文件

if (files[i].exists() !files[i].isDirectory()) {

String zjhmImg = files[i].getName();

if (zjhmMap.get(zjhmImg) != null) {

num++;

FileInputStream fi = new FileInputStream(files[i]);

origin = new BufferedInputStream(fi, BUFFER);

ZipEntry entry = new ZipEntry(files[i].getName());

out.putNextEntry(entry);

int count;

while ((count = origin.read(data, 0, BUFFER)) != -1) {

out.write(data, 0, count);

}

out.setEncoding("GBK");

origin.close();

关于Java批次和java批次查询的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-22,除非注明,否则均为首码项目网原创文章,转载请注明出处。