[英]Incorrect string value - JOOQ - Java
我正在尝试使用jooq将csv上传到我的mysql数据库中,但我却一直遵循以下错误。我尝试了网络上建议的各种解决方案,但无法修复
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字符记录都无法保存到数据库中并抛出上述错误。
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 Rest读取文件
InputStream inputStream = listingFilePart.getBody(InputStream.class, null);
并在传递给jooq之前在本地系统中递归写入文件
PrintWriter fop = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, true), StandardCharsets.UTF_8));
我将数据库设置为接受utf-8,并验证了相同的内容
我发现了问题。问题正在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);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.