mysql - Flyway migration, Unable to obtain Jdbc connection from DataSource -


i trying use flyway create , manage mysql database. here code have got far.

flywaymigration.java : class applys migration

public class flywaymigration {     public flywaymigration(databaseconfiguration configuration, flyway flyway)     {         flyway.setdatasource(configuration.getdatasource());         flyway.migrate();     }      public static void main(string[] args)     {         new flywaymigration(new databaseconfiguration("database.properties"), new flyway());     } } 

databaseconfiguration.java : configuration class, class configure datasource applyed flyway.setdatasource method

public class databaseconfiguration {     private final logger logger = loggerfactory.getlogger(this.getclass());      private propertiesutil prop = null;      public databaseconfiguration(string file)     {         prop = new propertiesutil(file);     }      public string getdatasourceclass()     {         return prop.getproperty("mysql.data.source.class");     }      public string geturl ()     {         return prop.getproperty("mysql.url");     }      public string gethostname()     {         return prop.getproperty("mysql.host.name");     }      public string getdatabasename()     {         return prop.getproperty("mysql.database.name");     }      public datasource getdatasource()     {         mysqldatasource datasource = new mysqldatasource();         datasource.seturl(geturl());         datasource.setuser(prop.getproperty("mysql.user.name"));         datasource.setpassword(null);         return datasource;     } } 

database.properties file store database information, password can null

mysql.data.source.class=com.mysql.jdbc.driver     mysql.url=jdbc:mysql://localhost:3306/vmrdb     mysql.host.name=localhost     mysql.database.name=vmrdb     mysql.user.name=root 

and folowing error in trace

exception in thread "main" org.flywaydb.core.api.flywayexception: unable obtain jdbc connection datasource     @ org.flywaydb.core.internal.util.jdbc.jdbcutils.openconnection(jdbcutils.java:56)     @ org.flywaydb.core.flyway.execute(flyway.java:1144)     @ org.flywaydb.core.flyway.migrate(flyway.java:811)     @ com.bt.sitb.vmr.migration.flywaymigration.<init>(flywaymigration.java:10)     @ com.bt.sitb.vmr.migration.flywaymigration.main(flywaymigration.java:15)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:483)     @ com.intellij.rt.execution.application.appmain.main(appmain.java:134) caused by: com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure 

can please tell me why datasource mysql not connecting. thanks!

it looks flyway cannot connect database.

one reason database in database url not exist.

question: database schema exist?

if answer no, then:

  • connect jdbc:mysql://localhost:3306/mysql
  • also specify schema use migration flyway.setschemas(configuration.getdatabasename())
  • you need flyway.init() before can initialize migration of database.

Comments

Popular posts from this blog

sql server - MSSQL Text and Varchar(MAX) fields shown (MEMO) in DBGrid -

qml - Is it possible to implement SystemTrayIcon functionality in Qt Quick application -

double exclamation marks in haskell -