我想增加我的CSV文件名csv1,csv2的输出我还要Zip创建的CSV文件命名约定应该像zip1和zip2一样增加zip1的内容是csv1而zip2是csv2 < / p>
public void process(Variables variables) throws SQLException, IOException{//CUST ORDER FILE
try{
log.info("Processing table");
connection connect = new connection();
connect.setConnection(variables);
if (variables.conn!= null){
Statement stmt = variables.conn.createStatement();
String query="SELECT (SELECT SBS FROM STOREDEF WHERE STOREID=4) AS BRANCH, OD.DT_DATE as TRANS_DATE, OC.ORDER_CODE, \n" +
"OD.ORDER_BARCODE,OC.FIRST_NAME,OC.LAST_NAME,OC.ADDRESS,OC.CITY,OC.DISTRICT,OC.PHONE,OC.STATE, '' as DEL_DATE \n" +
",OH.AMOUNT_ALREADY_PAID, OD.DT_TIME, \n" +
"CASE OD.DEPTNUM \n" +
"WHEN '90003' THEN '1' \n" +
"WHEN '90099' THEN '2' \n" +
"END AS ORDER_TYPE,TO.TID,TO.XACTNBR,'' AS ITEM_ORIGIN,OC.CUSTOMER_CODE AS ZONE_FIELD \n" +
"FROM ORDERS_CUSTOMERS OC \n" +
"LEFT JOIN ORDERS_DETAILS OD \n" +
"ON OC.ORDER_CODE = OD.ORDER_CODE \n" +
"LEFT JOIN ORDERS_HEADER OH \n" +
"ON OC.ORDER_CODE=OH.ORDER_CODE \n" +
"LEFT JOIN TL_ORDERS TO \n" +
"ON OC.ORDER_CODE=TO.ORDERCODE \n" +
"WHERE OD.DT_DATE = '2016-07-19' AND OD.DT_TIME BETWEEN '10:00:00' AND '23:00:00'";
ResultSet myRs = stmt.executeQuery(query);
log.info("Query executed");
if(myRs.next()){
String BRANCH =myRs.getString("BRANCH");
String TRANS_DATE = myRs.getString("TRANS_DATE");
String ORDER_CODE = myRs.getString("ORDER_CODE");
String ORDER_BARCODE = myRs.getString("ORDER_BARCODE");
String FIRST_NAME = myRs.getString("FIRST_NAME");
String LAST_NAME = myRs.getString("LAST_NAME");
String ADDRESS = myRs.getString("ADDRESS");
String CITY = myRs.getString("CITY");
String DISTRICT = myRs.getString("DISTRICT");
String PHONE = myRs.getString("PHONE");
String STATE = myRs.getString("STATE");
String DEL_DATE =myRs.getString("DEL_DATE");
String AMOUNT_ALREADY_PAID = myRs.getString("AMOUNT_ALREADY_PAID");
String ORDER_TYPE = myRs.getString("ORDER_TYPE");
String TID = myRs.getString("TID");
String XACTNBR = myRs.getString("XACTNBR");
String ITEM_ORIGIN = myRs.getString("ITEM_ORIGIN");
String ZONE_FIELD = myRs.getString("ZONE_FIELD");
}
Date date = new Date() ;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss") ;
String CSVFile = "C:\\Vstore\\OurHome\\sales\\CUSTOURHOMEMEGAMALL123"+dateFormat.format(date)+".CSV";
CSVWriter writer = new CSVWriter(new FileWriter(CSVFile),
'|',
CSVWriter.NO_QUOTE_CHARACTER,
CSVWriter.NO_ESCAPE_CHARACTER,
"\r\n");
String[] header = {"BRANCH"+
"|TRANS_DATE"+
"|ORDER_CODE"+
"|ORDER_BARCODE"+
"|FIRST_NAME"+
"|LAST_NAME"+
"|ADDRESS"+
"|CITY"+
"|DISTRICT"+
"|PHONE"+
"|STATE"+
"|DEL_DATE"+
"|AMOUNT_ALREADY_PAID"+
"|ORDER_TYPE"+
"|TID"+
"|XACTNBR"+
"|ITEM_ORIGIN"+
"|CUSTOMER_CODE"};
writer.writeNext(header);
writer.writeAll(myRs,false);
log.info("csv created");
writer.close();
myRs.close();
stmt.close();
}
variables.conn.close();
log.info("done processing");
} catch(Exception e){
log.error("Error in processing");
}
}
答案 0 :(得分:0)
文件获取您惊讶的传递给FileWriter()构造函数的名称。
所以你唯一要做的就是:
String numberedCsvFile = csvFileName +&#34; 1&#34;;
例如。
当然,真正的诀窍是:跟踪已经创建的csv文件。有两种方法可以实现:
要了解如何在java中创建ZIP文件,您可以开始阅读here。
一些注意事项: