Reputation: 487
I am using the Liquibase java API to update my database from a databaseChangeLog file. The code is running but the changes are not reflected in the database. The code is as follows:
public class testclass {
public static void main(String[] args) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@a_valid_hostname:1521:db11gr2",
"[username]", "[password]");
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn));
DatabaseChangeLog log = new DatabaseChangeLog("E:\\Delta.xml");
Liquibase liquibase = new liquibase.Liquibase(log, new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
System.out.println("COMPLETED");
}catch(Exception e){
e.printStackTrace();
}
}
}
Am I doing something wrong? Please help me out.
Upvotes: 3
Views: 2722
Reputation: 1
It works that initializing Liquibase with String as first parameter instead of DatabaseChangeLog. Example as below:
final Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test?useSSL=false", "***", "***");
final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(
new JdbcConnection(connection)
);
final Liquibase liquibase = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
Upvotes: 0
Reputation: 31
Since the OP didn't post how he managed to get this to work, I'm posting a working code here. Mind you, I'm using json ChangeLog and MySQL.
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://*****/test",
"****", "****");
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn));
Liquibase liquibase = new Liquibase("test.json", new FileSystemResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
} catch(Exception e){
// ...
}
Upvotes: 1
Reputation: 4263
Looking at your code more closely, I suspect that you may be using the wrong type of ResourceAccessor
.
Is the file "E:\\Delta.xml"
actually on your classpath? If not, change this line
Liquibase liquibase = new liquibase.Liquibase(log, new ClassLoaderResourceAccessor(), database);
To
Liquibase liquibase = new liquibase.Liquibase(log, new FileSystemResourceAccessor(), database);
This tells liquibase to read the changelog file from the filesystem, not the classpath.
Upvotes: 4