Spring Mvc Hibernate编码/多行导入sql [英] Spring Mvc Hibernate Encoding/Multi-line import sql

查看:160
本文介绍了Spring Mvc Hibernate编码/多行导入sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring MVC,

在项目启动时,我设置了数据库来导入默认值 sql
with hibernate configuration hibernate.hbm2ddl.import_files
import.sql 中的数据以 UTF-8 编码。


控制台输出




 错误: org.hibernate.tool.hbm2ddl.SchemaExport  -  HHH000388:
不成功:INSERT INTO菜单(ID,DATE_CREATED,DATE_DELETED,
DATE_UPDATED,TITLE_ENG,TITLE_GEO,TITLE_RUS,ENABLED,PARENT_ID,
URL, SITE_ID,USER_ID)值

错误:
org.hibernate.tool.hbm2ddl.SchemaExport - 您的
SQL语法中有错误;检查与您的MySQL服务器
对应的手册,在第1行附近使用正确的语法

错误:
org.hibernate.tool.hbm2ddl.SchemaExport - HHH000388:不成功:(1,
'2015-09-10 12:00:00',NULL,NULL,'关于我们',N'Ⴣƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ¡ 关于我们,b'1',NULL,'/ article / view / 1',3,
1)。


解决方案


  1. 制作确保你设置的JDBC驱动程序使用UTF-8:
    $ b

    jdbc:mysql:// dbname?useUnicode = true& characterEncoding = utf- 8


  2. persistence.xml 中,设置hibernate连接字符集:



    < property name =hibernate.connection.charSetvalue =UTF-8/>


如果您的 resources / import.sql -line,add:

 < 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


I am working on Spring MVC,

On project startup i have set database to import default sql with hibernate configuration hibernate.hbm2ddl.import_files. Data inside import.sql is encoded with 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, NULL, 'About Us', N'ჩვáƒ"ნს
 შáƒ"სáƒ�ხáƒ"ბ', 'About Us', b'1', NULL, '/article/view/1', 3,
 1).

解决方案

  1. Make sure you are setting the JDBC driver to use UTF-8:

    jdbc:mysql://dbname?useUnicode=true&characterEncoding=utf-8

  2. In persistence.xml, set the hibernate connection charset:

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

If your resources/import.sql file is multi-line, add:

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

or for Spring Boot, in application.properties:

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

这篇关于Spring Mvc Hibernate编码/多行导入sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆