I'm trying to get some old code working thats creates some tables for a hibernate configuration in a Mysql Database, but the code referred to a datasource config that I no longer have and I just want to run it as standalone Java (not within Tomcat container) so Ive made some changes to Hibernate config.
My pom now includes
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
My code is
public static Configuration setupDatabase()
{
Configuration cfg = new Configuration()
.setProperty(Environment.URL,"jdbc:mysql:songkong")
.setProperty(Environment.DRIVER,"com.mysql.fabric.jdbc.FabricMySQLDriver")
.setProperty(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect")
.setProperty("hibernate.show_sql", "true")
.setProperty("hibernate.connection.username","dbuser")
.setProperty("hibernate.connection.username", "dbpassword");;
addEntitiesToConfig(cfg);
cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
return cfg;
}
public static void main(String[] args)
{
Configuration cfg = setupDatabase();
new SchemaExport(cfg).create(false,true);
}
Currently the problem is it cant find the driver.
java.sql.SQLException: No suitable driver found for jdbc:mysql:songkong
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:173)
at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:55)
at org.hibernate.tool.hbm2ddl.DatabaseExporter.<init>(DatabaseExporter.java:52)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:368)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:305)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:294)
at com.jthink.songkong.appserverdb.util.Db.main(Db.java:143)
The Fabric driver is in the jar but Im not sure if I should be using this driver, and if the Environment.DRIVER line is set correctly to refer to it. I don't think I used this driver before ( a couple of years ago) but it was the only one i could find in maven central.
(My database is called songkong and i can correct to it correctly from commandline, I don't show real username and password in code excerpt)