2014年11月7日 星期五

BufferedReader example ->texttoInsertSql

 texttoInsertSql:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package acerrcode;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author linkulife
 */
public class AcerRcode {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

       
        File file = null;

        file = new File("D:\\keith\\linkulife\\AcerRcode.txt");
       readfileByLine(file);

    }

    public static void readfileByLine(File file) {
        ArrayList<String[]> list = new ArrayList<String[]>();
        InputStreamReader isr = null;
        try {
            try {
                isr = new InputStreamReader(new FileInputStream(file), "UTF-8");
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(AcerRcode.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(AcerRcode.class.getName()).log(Level.SEVERE, null, ex);
        }
        BufferedReader br = new BufferedReader(isr);
        String str = null;

        try {
            while((str = br.readLine())!=null){
              
                 list.add(parseTosql(str));
            }
           
        } catch (IOException ex) {
            Logger.getLogger(AcerRcode.class.getName()).log(Level.SEVERE, null, ex);
        }
        //System.out.println(Arrays.toString(list));

    }

    public static String[] parseTosql(String line) {
        String[] linearray = line.split("\\s+");
        //System.out.println(Arrays.toString(linearray));
        String sql=setToSql(linearray[0],linearray[1],linearray[2],linearray[3]);
        System.out.println(sql);
        return linearray;
      
    }

    public static String setToSql(String acerCode, String acerResponse, String ewalletCode, String appShowMsg) {
        String temp = "INSERT INTO `ewalletValue`.`acerResponse` (`acerResponseId`, `acerCode`, `acerResponse`, `ewalletCode`, `appShowMsg`) VALUES (NULL"
                + ", '" + acerCode + "', '" + acerResponse + "', '" + ewalletCode + "', '" + appShowMsg + "');";
        return temp;
    }

}

input:
00    授權成功    A00    交易成功
01    請查詢發卡銀行    A01    交易失敗(A01):請洽原發卡行
02    請查詢發卡銀行    A02    交易失敗(A02):請洽原發卡行
03    未核准之特約店    A03    交易失敗(A03):請洽客服
04    非正常卡    A04    交易失敗(A04):卡片異常,請洽原發卡行
05    拒絕交易    A05    交易失敗(A05):拒絕交易,請洽客服
12    本交易不接受    A12    交易失敗(A12):拒絕交易,請洽客服
13    金額不符    A13    交易失敗(A13):請洽客服
14    帳號不符    A14    交易失敗(A14):請洽客服
15    原發卡行不符    A15    交易失敗(A15):請洽客服
19    請重試交易    A19    交易失敗(A19):請洽原發卡行確認交易結果
25    請查詢銀行    A25    交易失敗(A25):請洽原發卡行
30    請查詢銀行    A30    交易失敗(A30):請洽原發卡行
31    本交易不接受    A31    交易失敗(A31):拒絕交易,請洽客服
41    非正常卡    A41    交易失敗(A41):卡片異常,請洽原發卡行
43    非正常卡    A43    交易失敗(A43):卡片異常,請洽原發卡行
51    餘額不足    A51    交易失敗(A51):額度不足,請洽原發卡行
54    卡片過期    A54    交易失敗(A54):卡片過期,請洽原發卡行
55    密碼錯誤    A55    交易失敗(A55):請洽客服
57    本交易不接受    A57    交易失敗(A57):拒絕交易,請洽客服
58    本交易不接受    A58    交易失敗(A58):拒絕交易,請洽客服
59    無此帳號    A59    交易失敗(A59):請洽客服
61    提款超過限額    A61    交易失敗(A61):請洽原發卡行
62    非正常卡    A62    交易失敗(A62):卡片異常,請洽原發卡行
63    主機安全碼有誤    A63    交易失敗(A63):請洽客服
75    密碼超過次數    A75    交易失敗(A75):請洽客服
77    總額不符    A77    交易失敗(A77):請洽客服
79    批號已開啟    A79    交易失敗(A79):請洽客服
80    批號錯誤    A80    交易失敗(A80):請洽客服
85    無此批號    A85    交易失敗(A85):請洽客服
88    特約店帳號不符    A88    交易失敗(A88):請洽客服
89    終端機號錯誤    A89    交易失敗(A89):請洽客服
91    請查詢發卡銀行    A91    交易失敗(A91):請洽原發卡行
94    傳輸重覆    A94    交易失敗(A94):請洽客服
95    檔案傳輸中    A95    交易失敗(A95):請洽客服
96    主機系統故障    A96    交易失敗(A96):請洽客服
outpunt

沒有留言:

張貼留言