import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.sql.*;
import java.util.*;
public class Test {
public void createData(int a) {
Connection conn = null;
PreparedStatement pstmt = null;
try{
String dburl = "数据源URL";
String username = "数据库用户名";
String password = "数据库密码";
conn = DriverManager.getConnection(dburl, username, password);
String sql = "insert into tbl_dconl_temp(copon_desc,coupon_id) values (?,?) on duplicate key update copon_desc = ?";
pstmt = (PreparedStatement)conn.prepareStatement(sql);
long starttime=System.currentTimeMillis();
String path = "D:\\rpt\\number\\coupon_desc2";
File file = new File(path);
File filelist[] = file.listFiles();
for (File f : filelist) {
String filename = f.getName();
if (filename.endsWith("html")) {
String f1 = new String(f.getAbsolutePath());
String couponId = filename.substring(0,filename.lastIndexOf("."));
String coponDesc = readeFile(f1);
pstmt.setString(1, coponDesc);
pstmt.setString(2, couponId);
pstmt.setString(3, coponDesc);
pstmt.addBatch();
//执行sql语句
pstmt.executeBatch();
pstmt.clearBatch();
long endtime=System.currentTimeMillis();
System.out.println("十万数据耗时++++++++++++++++++++"+(endtime-starttime));
logger.info("结束");
}
}
/*
String sql = "INSERT INTO tableName(order_id, user_id, trans_dt, \n" +
" trans_mon, trans_tm, batch_dt, \n" +
" trans_tp, trans_at, proc_st, \n" +
" reason_cd, act_no, act_nm, buss_tp, \n" +
" buss_sub_tp, cups_pk, cups_trans_at, \n" +
" cups_mchnt_cd, cups_mchnt_nm, cups_pay_md, \n" +
" cups_refund_at, src_id, orig_order_id, \n" +
" orig_trans_dt, orig_cups_pk, orig_batch_dt) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?)";
pstmt = (PreparedStatement) conn.prepareStatement(sql);
long starttime = System.currentTimeMillis();
for(int j=1;j<=10;j++){// 17 93751 62501 31251
for(int i=1;i<10001;i++){
int jx91 = (int)(Math.random()*1000000000+1);
pstmt.setString(1,"8"+i+jx91);
int jx92 = (int)(Math.random()*1000000000-1);
pstmt.setString(2, "0"+j+jx92);
pstmt.setString(3,"20200331");
pstmt.setInt(4,3);
int jx93 = (int)(Math.random()*100+1);
pstmt.setString(5,"09"+jx93);
pstmt.setString(6,"20200331");
if(j==1 || j==2) {
pstmt.setString(7,"01");
}if(j==3 || j==4) {
pstmt.setString(7,"99");
}
pstmt.setInt(8,jx93);
pstmt.setString(9,"01");
pstmt.setString(10,"PGONE001");
pstmt.setString(11,"测试活动");
pstmt.setString(12,"活动编号");
pstmt.setString(13,"01");
pstmt.setString(14,"01");
pstmt.setString(15,"F7");
pstmt.setInt(16,jx92);
pstmt.setString(17,"10001001");
pstmt.setString(18,"F7");
pstmt.setString(19,"01");
pstmt.setString(20,"0");
pstmt.setString(21,"01");
double jx96 = (Math.random()*1000+1);
pstmt.setString(22,jx91+"0"+jx96);
pstmt.setString(23,"20200320");
pstmt.setString(24,"F7");
pstmt.setString(25,"20200331");
pstmt.addBatch();
}
j=j++;
System.out.println(j);
pstmt.executeBatch();
pstmt.clearBatch();
}
long endtime=System.currentTimeMillis();
System.out.println("十万数据耗时++++++++++++++++++++"+(endtime-starttime));
*/
} catch (Exception e){
logger.info("错"+e);
}
}
}
}
private static String readeFile(String filePath) {
FileInputStream input = null;
String result = "";
try {
//1.根据path实例化一个输入流的对象
input = new FileInputStream(filePath);
//2.返回这个输入流中可以被读的剩下的bytes字节的估计值;
int size = input.available();
//3.根据输入流的字节创建一个byte数组
byte[] array = new byte[size];
//4.把数据读取到byte数组中
input.read(array);
//5.根据获取的byte数组新建一个字符串,然后输出
result = new String(array);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(input != null){
try {
//关闭
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
//测试输出是否正常
public static void main(String[] args) {
String path = "D:\\rpt\\number\\CPN00000000231.html";
String input = readeFile(path);
System.out.println(input);
}