加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Spring Mvc Hibernate编码/多行导入sql

发布时间:2020-12-15 04:30:10 所属栏目:Java 来源:网络整理
导读:我正在研究 Spring MVC, 在项目启动时,我已设置数据库以导入默认sql 使用hibernate配置hibernate.hbm2ddl.import_files. import.sql中的数据使用UTF-8编码. Console Output ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - HHH000388: Unsuccessful: INSE
我正在研究 Spring MVC,

在项目启动时,我已设置数据库以导入默认sql
使用hibernate配置hibernate.hbm2ddl.import_files.
import.sql中的数据使用UTF-8编码.

Console Output

ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - HHH000388:
 Unsuccessful: INSERT INTO menu (id,DATE_CREATED,DATE_DELETED,DATE_UPDATED,TITLE_ENG,TITLE_GEO,TITLE_RUS,ENABLED,PARENT_ID,URL,SITE_ID,USER_ID) VALUES 

 ERROR:
 org.hibernate.tool.hbm2ddl.SchemaExport - You have an error in your
 SQL syntax; check the manual that corresponds to your MySQL server
 version for the right syntax to use near '' at line 1

 ERROR:
 org.hibernate.tool.hbm2ddl.SchemaExport - HHH000388: Unsuccessful: (1,'2015-09-10 12:00:00',NULL,'About Us',N'á??á??á?”á??á??
 á?¨á?”á??á??á??á?”á?‘',b'1','/article/view/1',3,1).

解决方法

>确保将JDBC驱动程序设置为使用UTF-8:

JDBC:MySQL的:// DBNAME了useUnicode =真安培;的characterEncoding = UTF-8
>在persistence.xml中,设置hibernate连接字符集:

< property name =“hibernate.connection.charSet”value =“UTF-8”/>

如果您的resources / import.sql文件是多行的,请添加:

<property 
  name="hibernate.hbm2ddl.import_files_sql_extractor"
  value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" 
/>

或者对于Spring Boot,在application.properties中:

spring.jpa.properties.hibernate.connection.charSet=UTF-8
spring.jpa.properties.hibernate.hbm2ddl.import_files_sql_extractor=org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读