Hibernate + Dropwizard,MySQLSyntaxErrorException:未知数据库'test_db;'

时间:2017-02-09 21:29:36

标签: java hibernate dropwizard

我有一个简单的dropwizard应用程序,我已经为配置编写了以下yml。

template: Hello, %s!
defaultName: Stranger
database:
  driverClass: com.mysql.jdbc.Driver
  user: rootUser
  password: rootPassword
  url: jdbc:mysql://<SQL SERVER IP>:<SQL SERVER IP>/test_db;
  properties:
    charSet: UTF-8
    hibernate.dialect: org.hibernate.dialect.MySQLDialect

以下是我在应用程序的“运行”方法中添加它的方法:

    // Setting up the database.
    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "mysql");

    //Hibernate
    final UserDAO dao = new UserDAO(hibernate.getSessionFactory());
    environment.jersey().register(new UserResource(dao));

另外,在同一个类中,我有以下方法,它引入了hibernate包:

private final HibernateBundle<ServerConfiguration> hibernate = new HibernateBundle<ServerConfiguration>(User.class) {
    @Override
    public DataSourceFactory getDataSourceFactory(ServerConfiguration configuration) {
        return configuration.getDataSourceFactory();
    }
};

现在,这一切都构建了,但是当我尝试运行jar并同时使用yml文件时......我收到以下错误:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'test_db;'

我知道db就在那个位置,因为我使用dBeaver将记录添加到tbl_users表中。

任何想法,有人吗?

1 个答案:

答案 0 :(得分:2)

从database.url属性中删除尾随;,它将起作用。尾部;作为数据库名称的一部分包含在内,导致失败。