2017-02-09 26 views
0

我有一個簡單的dropwizard應用程序,並且我已經爲配置編寫了以下yml。Hibernate + Dropwizard,MySQLSyntaxErrorException:未知數據庫'test_db;'

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)); 

而且,在同一個班級,我有以下的方法,這使發揮作用,休眠束:

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表中。

任何想法,任何人?

+0

您確定服務器IP和端口在您的JDBC URL上正確嗎? – Naros

+0

是的,100% - 我可以通過SQL客戶端中的這些細節連接到它。 – MickeyThreeSheds

回答

2

從你的database.url屬性中刪除尾隨的;,它將起作用。尾部的;正在作爲導致失敗的數據庫名稱的一部分被包括在內。

相關問題