【问题标题】:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException in hibernate program which ask for check mysql versioncom.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException 在休眠程序中要求检查 mysql 版本
【发布时间】:2017-04-29 09:26:43
【问题描述】:

在基于休眠的程序中编程时出现以下异常com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

MySql 版本是 5.7.9,我的方言是 org.hibernate.dialect.MySQLDialect。

【问题讨论】:

  • 试试org.hibernate.dialect.MySQL5Dialect
  • 我也尝试过使用 org.hibernate.dialect.MySQL5Dialect 但仍然出现错误
  • 请发布您的错误堆栈和 jdbc 配置。
  • Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“add, name, id) values ('godhra', 'raj', 1)' 附近使用正确的语法
  • @Raj 请在 Question not in cmets 中发布您的错误堆栈和配置。

标签: java mysql hibernate


【解决方案1】:

要构建 SessionFactory 对象,请使用下面的代码 sn-p 并确保 hibernate.cfg.xml 在类路径中。

try 
{
    Configuration configuration = new Configuration();
    configuration.configure();
    SessionFactory sessionFactory = configuration
                .buildSessionFactory(new StandardServiceRegistryBuilder()
                        .applySettings(configuration.getProperties())
                        .build());
} catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException(
            "There was an error building the factory");
}

【讨论】:

    猜你喜欢
    • 2015-05-28
    • 2012-07-20
    • 1970-01-01
    • 2018-03-11
    • 2012-04-20
    • 2015-09-23
    • 2016-10-25
    • 2013-11-20
    • 2016-07-07
    相关资源
    最近更新 更多