字符串值不正确:第 1 行错误的第 'pic_byte' 列的“\x9C\x94\xBAw4\x9C...”
Incorrect string value: '\x9C\x94\xBAw4\x9C...' for column 'pic_byte' at row 1 error
我正在尝试发送带有图像的 post 请求,但我不断收到以下错误:
java.sql.SQLException: Incorrect string value: '\x9C\x94\xBAw4\x9C...' for column 'pic_byte' at row 1
我找到的一个解决方案是使用以下查询将 UTF8 转换为 UTF8MB4:
ALTER TABLE database.table MODIFY COLUMN col VARCHAR(255)
CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;
但是我仍然遇到同样的错误。如果有帮助,下面是我的 post 方法:
@PostMapping("/upload")
public ResponseEntity.BodyBuilder uploadImage(@RequestParam("imageFile") MultipartFile file) throws IOException {
System.out.println("Original Image Byte Size - " + file.getBytes().length);
model img = new model(file.getOriginalFilename(), file.getContentType(),
compressBytes(file.getBytes()));
userRepository.save(img);
return ResponseEntity.status(HttpStatus.OK);
}
我该如何解决这个问题?我需要在我的 application.properties 文件中设置一些特定的配置吗?
用四个字节编码的字符的开头。
alter table `tablename`
modify column col VARCHAR(255
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL ;
我正在尝试发送带有图像的 post 请求,但我不断收到以下错误:
java.sql.SQLException: Incorrect string value: '\x9C\x94\xBAw4\x9C...' for column 'pic_byte' at row 1
我找到的一个解决方案是使用以下查询将 UTF8 转换为 UTF8MB4:
ALTER TABLE database.table MODIFY COLUMN col VARCHAR(255)
CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;
但是我仍然遇到同样的错误。如果有帮助,下面是我的 post 方法:
@PostMapping("/upload")
public ResponseEntity.BodyBuilder uploadImage(@RequestParam("imageFile") MultipartFile file) throws IOException {
System.out.println("Original Image Byte Size - " + file.getBytes().length);
model img = new model(file.getOriginalFilename(), file.getContentType(),
compressBytes(file.getBytes()));
userRepository.save(img);
return ResponseEntity.status(HttpStatus.OK);
}
我该如何解决这个问题?我需要在我的 application.properties 文件中设置一些特定的配置吗?
用四个字节编码的字符的开头。
alter table `tablename`
modify column col VARCHAR(255
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL ;