15

I am utilising Liquibase (www.liquibase.org) into our MVC3 SQL Server 2008 project to manage database migration/changes. However I'm stumbling on the first hurdle: Connecting to Microsoft SQL Server instance.

I am looking at the quick start tutorial on the liquibase site, but exchanging the mysql for sql server DB

I run this command:

liquibase --driver=sqljdbc.jar  --changeLogFile="C:\Temp\ChangeLog.xml"  --url="jdbc:sqlserver://localhost;databaseName=test"  --username=user --password=pass   migrate

And receive this error:

Liquibase Update Failed: Cannot find database driver: sqljdbc.jar

I have tried adding --classpath pointing to the sqljdbc driver with no luck.

How can I create or update an MS-SQL Server database with liquibase?

JaneGoodall
  • 1,478
  • 2
  • 15
  • 22
Dan Black
  • 1,167
  • 3
  • 14
  • 20

1 Answers1

25

Create a properties file called liquibase.properties containing the following:

classpath=C:\\Program Files\\Microsoft SQL Server 2005 JDBC Driver\\sqljdbc_1.2\\enu\\sqljdbc.jar
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url=jdbc:sqlserver://localhost:1433;databaseName=test
username=myuser
password=mypass
changeLogFile=C:\\Temp\\ChangeLog.xml

liquibase will use this file when located in the same directory. Useful to simplify the command-line.

Database is updated as follows:

liquibase update

Notes:

  • I'm not a SQL server user, I picked up the JDBC driver and URL details from Microsoft doco
  • The "migrate" command has been deprecated.
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • 2
    Brilliant. Thanks a lot Mark. Used the newer mssql jdbc 3.0 driver and added double backslash to locations e.g C:\\Program Files\\Microsoft...... – Dan Black Jan 25 '12 at 10:05
  • 1
    Thanks very much for your help... But I keep asking myself... how they don´t put this kind of info on docs page? – Fernando Vieira Apr 03 '14 at 19:56
  • Its not advisable to use absolute path for the parameter ```changeLogFile=C:\\Temp\\ChangeLog.xml``` because the absolute path will differ from programmer to programmer as he/she chosen. . Liquibase uses the change set ID, author and filename to create a check sum to validate if a change has already been processed. (http://forum.liquibase.org/topic/why-does-the-change-log-contain-the-file-name). So, it's better to include directory name in ```classpath``` parameter as suggested by @nvoxlandas in the forum mentioned. – Paramesh Korrakuti Jan 04 '18 at 04:53
  • 1
    @ParameshKorrakuti I fully accept your point. The answer is 3 years old, dating back to a time when I was chained to a windows workstation... there I found that explicitly stating the full directory pathname worked more reliably in Java.... Fortunately this is all a dim and distant memory :-) Thank you for your comment – Mark O'Connor Apr 06 '18 at 16:22