2017-09-06 26 views
0

我試圖上傳CSV文件到我的MySQL數據庫使用jooq如何我曾經得到以下error.I嘗試了各種解決方案的淨建議,但不能修復它不正確的字符串值 - JOOQ - Java的

Error: org.jooq.exception.DataAccessException: SQL [insert into `Test`.`testtable` <mydata> Incorrect string value: '\xEF\xBF\xBD15 ...' for column 'colum_Name' at row 1 

我如何我上傳的CSV jooq

create.loadInto(Tables.TableName) 
               .onErrorIgnore() 
               .loadCSV(new File("/tmp/uploaded-files/" + fileName), "UTF-8").<fields>.execute(); 

我保證文件是UTF-8然而,當曾經有UTF-8字符的記錄未能在DB保存及以上error.I投擲使用

file -i <filename> 
保證

前端AJAX:

$.ajax({ 
    type: "POST", 
    enctype: 'multipart/form-data', 
    url: fileUploadUrl, 
    data: dataforFileUpload, 
    processData: false, 
    contentType: false, 
    cache: false, 
    timeout: 600000, 
    success: function (message) { 
     console.log(message); 
     alert(message); 
     console.log("upload done "+ new Date()); 

    }, 
    error: function (e) { 
     console.log("ERROR : ", e.responseText); 
     alert("ERROR : "+ e.responseText); 

    } 
}); 

我從我的前端通過java讀它獲取文件休息

InputStream inputStream = listingFilePart.getBody(InputStream.class, null); 

,並傳遞給jooq

PrintWriter fop = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, true), StandardCharsets.UTF_8)); 
之前在本地系統遞歸編寫文件

我將我的數據庫設置爲接受utf-8,並驗證了相同的

回答

0

我發現問題。問題是在ajax調用。 我需要發送字符集enctype

$.ajax({ 
    type: "POST", 
    enctype: 'multipart/form-data;charset=UTF-8', 
    url: fileUploadUrl, 
    data: dataforFileUpload, 
    processData: false, 
    contentType: false, 
    cache: false, 
    timeout: 600000, 
    success: function (message) { 
     console.log(message); 
     alert(message); 
     console.log("upload done "+ new Date()); 

    }, 
    error: function (e) { 
     console.log("ERROR : ", e.responseText); 
     alert("ERROR : "+ e.responseText); 

    } 
});