Hi,
I'm using Liquibase directly from Java 8, after adding the
Maven dependency for Liquibase 3.4.0.
My project includes some database interactions with an Oracle 11g
database (I included ojdbc6.jar in the build path and
liquibase-oracle-3.0.0.jar as a maven dependency). My changelog
is composed with a single changeset of creating a table if it
doesn't exist (precondition with
onSQLOutput="TEST"). When I run this changelog with
the command line, everything works fine, but when I launch it with my
Java application, something goes wrong (my simplified java code is
written down below).
With the update action, this task simply does nothing. With
updateSQL or futureRollbackSQL, it generates a file
creating the tables of Liquibase (databasechangelog and
databasechangeloglock), but does not include my changeset.
I'm 100% sure that the table does not exist on the given database.
I'm a little lost now, I don't know what to do or
what's wrong. I checked at some examples from other topics, but I
can't see any error in my code in my code (well... there should be
one, obviously). Even posted this question on stackoverflow and
didn't get any answer.
So I would be very grateful if you could help me point out my
mistake(s) on this application !
Tell me if you need more details.
Thank you for your answers.
Java Code
- Connection c = null;
- Database database = null;
- PrintWriter pw = null;
- File file = null;
- liquibase.Liquibase liquibase = null;
- contexts = db+"."+user;
- try {
- pw = new PrintWriter(new FileWriter(file));
- // Get connection
- c = SQLManager.getInstance().getConnection(db, user, passwd);
- // Get liquibase connection
- database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(c));
- liquibase = new liquibase.Liquibase(new DatabaseChangeLog(fsource), new FileSystemResourceAccessor(),
- database);
- // Run liquibase action
- switch (realAction) {
- case Constants.LIQUIBASE_ACTION_FUTUREROLLBACKSQL:
- liquibase.futureRollbackSQL(pw);
- break;
- case Constants.LIQUIBASE_ACTION_UPDATESQL:
- liquibase.update(contexts, pw);
- break;
- case Constants.LIQUIBASE_ACTION_UPDATE:
- liquibase.update(contexts);
- if (!c.getAutoCommit())
- c.commit();
- break;
- default:
- throw new RuntimeException("Action not implemented");
- }
- pw.close();
- database.close();
- c.close();
- } catch (IOException | SQLException | LiquibaseException e) {
- throw new Exception(e.getMessage());
- } finally {
- if (c != null) {
- try {
- c.close();
- } catch (SQLException e) {
- throw new RuntimeException(e.getClass() + ": " + e.getMessage());
- }
- }
- }