多线程
package com.evergrandelife;
import org.apache.commons.codec.digest.DigestUtils;
import java.io.*;
import java.security.MessageDigest;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
public class AllIndex_FTP {
public static Connection dbConn() {
Connection c = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
// c = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.163.84.201)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = hddb)))", "gapro", "RXC8SLNdhe");
c = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.163.84.201)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = hddb)))", "lis", "H55MARXjfa");
} catch (SQLException e) {
e.printStackTrace();
}
//System.out.println("---------------c:"+c);
return c;
}
public static String md5(String s) {
//加密后的字符串
//String s = "610125197706045541";
//UPPER(md5(upper(md5(upper('610125197706045541'))),'DYZEQ'))
/*610125197706045541 == 0BBB7588F9BCCAFF757A9619C80F7568
510213198206211655 == AC846575EE3D9D66E9B296E1F170CB01
410103199107110018 == 4285F72B40D04D9774F0C7A6E71FE0BA*/
s = DigestUtils.md5Hex(s.toUpperCase()).toUpperCase();
//System.out.println(s);
s = DigestUtils.md5Hex(s+"BDYZEQ").toUpperCase();
//System.out.println(s);
return s;
}
public static String write_path="E:\\PSV20200514\\";
public static void thread_write_PVS2018() {
class ThreadTest2 extends Thread{
private String s1;
private String s2;
public ThreadTest2(String s1,String s2) {
this.s1 = s1;
this.s2 = s2;
}
@Override
public void run() {
try {
Connection c = dbConn();
PreparedStatement ps = null;
ResultSet rs =null;
if(!new File(write_path).exists()) {
new File(write_path).mkdir();
}
try {
//File f = new File("f:\\PVS20180709\\"+s1+".success");
File f = new File(write_path+s1+".success");
f.createNewFile();
FileWriter out = new FileWriter(write_path+s1+".csv"); //文件写入流
BufferedWriter bw=new BufferedWriter(out);
String sql = "select * from PVS2020 aa where ss between 100000*"+s1+" and 100000*"+s2;
System.out.println(sql);
ps = c.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
String idno = rs.getString("IDNO");
String idno_md5 = md5(idno);
System.out.println(idno_md5+",0101");
bw.write(idno_md5+",0101");
bw.flush();
bw.newLine();
}
bw.close();
out.close();
}catch(Exception e) {
e.printStackTrace();
}
}catch(Exception e) {
e.printStackTrace();
}
}
}
ExecutorService pool = Executors.newFixedThreadPool(50);
for(int i=0;i<50;i++) {
int j=i+1;
pool.execute(new ThreadTest2(i+"",j+""));
}
pool.shutdown();
}
public static void main(String[] arg) throws Exception{
/*
drop table PVS2020;
create table PVS2020 as
SELECT rownum AS SS,dp.* FROM LDPERSON DP INNER JOIN LCCONT CC ON (CC.INSUREDNO = DP.CUSTOMERNO OR CC.APPNTNO = DP.CUSTOMERNO) WHERE DP.IDTYPE = '0';
*/
thread_write_PVS2018();
}
}

浙公网安备 33010602011771号