我正在使用新闻API将文章插入数据库。只要有引号或撇号,就会在其中放置这些怪异的字符,弄乱了所有东西。我在网上找到可以解决这些问题的查询,但是我需要将它们自动化,因为我每5个小时插入一次新文章。我在@Repository
中用Java语言编写了一个查询,以修复文章的标题和说明。该查询在MYSQL Workbench中有效,但是当我尝试在Java服务器中运行该查询时不起作用。这是查询:
@Modifying
@Transactional
@Query(
value =
"UPDATE networthr.articles SET description = REPLACE(description, '“', '“');\n"
+ "UPDATE networthr.articles SET description = REPLACE(description, 'â€�', '”');\n"
+ "UPDATE networthr.articles SET description = REPLACE(description, '’', '’');\n"
+ "UPDATE networthr.articles SET description = REPLACE(description, '‘', '‘');\n"
+ "UPDATE networthr.articles SET description = REPLACE(description, '—', '–');\n"
+ "UPDATE networthr.articles SET description = REPLACE(description, '–', '—');\n"
+ "UPDATE networthr.articles SET description = REPLACE(description, '•', '-');\n"
+ "UPDATE networthr.articles SET description = REPLACE(description, '…', '…');\n"
+ "\n"
+ "UPDATE networthr.articles SET title = REPLACE(title, '“', '“');\n"
+ "UPDATE networthr.articles SET title = REPLACE(title, 'â€�', '”');\n"
+ "UPDATE networthr.articles SET title = REPLACE(title, '’', '’');\n"
+ "UPDATE networthr.articles SET title = REPLACE(title, '‘', '‘');\n"
+ "UPDATE networthr.articles SET title = REPLACE(title, '—', '–');\n"
+ "UPDATE networthr.articles SET title = REPLACE(title, '–', '—');\n"
+ "UPDATE networthr.articles SET title = REPLACE(title, '•', '-');\n"
+ "UPDATE networthr.articles SET title = REPLACE(title, '…', '…');", nativeQuery = true)
void fixArticles();
当我尝试运行此查询时,它在第1行显示SQL语法错误,但我知道它在任何行上均不起作用。
谢谢您的回答。