【scala报错】java.sql.BatchUpdateException: Incorrect string value: ‘\xE4\xBA\xA7\xE5\x93\x81...‘ for co

【scala报错】java.sql.BatchUpdateException: Incorrect string value: '\xE4\xBA\xA7\xE5\x93\x81...' for column 'job_name' at row 1

1. Scenario
When using IDEA to write a scala program, in order to achieve an error when writing a MYSQL database from a CSV file.

2. Reasons The
utf-8 encoding is used in the program, but the encoding is not specified when the database is created. If the encoding is not specified, the default latin1 encoding will be used, which conflicts with the utf-8 encoding used by the program.

3.
Solution Steps to solve: check the encoding of the database and table, modify the encoding of the database and table, check the encoding of the database and table

1. View the encoding of the database and table
SHOW CREATE DATABASE mydb;

SHOW CREATE TABLE mydb.user;

2. Modify the encoding of the database and table
ALTER DATABASE mydb DEFAULT CHARACTER SET utf8;

ALTER TABLE mydb.user CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

3. Check the encoding of the database and table
SHOW CREATE DATABASE mydb;

SHOW CREATE TABLE mydb.user;

4. Verify that the
program can be executed successfully after running the program again.

Guess you like

Origin blog.csdn.net/debimeng/article/details/113101894
Recommended