>我正在尝试为部署到MS SQL Server 2014的数据库设置liquibase。当我尝试运行更新(使用命令行)时,我收到以下错误消息:
Unexpected error running Liquibase: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:1234;databaseName=mydb" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver. Possibly the wrong driver for the given database URL
我的属性文件是:
classpath=D:\Tools\Liquibase\Microsoft JDBC Driver 6.2 for SQL Server\sqljdbc_6.2\enu\mssql-jdbc-6.2.2.jre8.jar
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url="jdbc:sqlserver://myserver:1234;databaseName=mydb"
username=MyUserName
password=SomePassword
changeLogFile=D:\Tools\Liquibase\Test.sql
liquibase 批处理文件正在以下环境中运行:
Windows Server 2012
Java 1.8.0_31
我还使用 Microsoft 的 JDBC 示例代码测试了连接。我将 mssql-jdbc-6.2.2.jre8.jar 添加到我的项目中,并使用属性文件中的相同 url、用户名、数据库名称和密码成功运行查询。
String connectionUrl = "jdbc:sqlserver://myserver:1234;databaseName=mydb;user=MyUserName;password=SomePassword";
我确信我有正确的驱动程序并且可以建立连接。但是,我无法弄清楚出了什么问题。
调试日志:
SEVERE 3/1/18 1:54 PM: liquibase: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:2431;databaseName=mydb;" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver.
Possibly the wrong driver for the given database URL
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:2431;databaseName=mydb;" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver.
Possibly the wrong driver for the given database URL
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:127)
at liquibase.integration.commandline.Main.doMigration(Main.java:958)
at liquibase.integration.commandline.Main.run(Main.java:188)
at liquibase.integration.commandline.Main.main(Main.java:103)
Caused by: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:2431;databaseName=mydb;" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver. Possibly the wrong driver for the given database URL
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:247)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85)
... 3 more
Caused by: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:2431;databaseName=mydb;" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver. Possibly the wrong driver for the given database URL
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:242)
... 5 more
解决:
classpath=D:\Tools\Liquibase\Microsoft JDBC Driver 6.2 for SQL Server\sqljdbc_6.2\enu\mssql-jdbc-6.2.2.jre8.jar
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url=jdbc:sqlserver://myserver:1234;databaseName=mydb
username=MyUserName
password=SomePassword
changeLogFile=D:\Tools\Liquibase\Test.sql
我发现了问题。问题是属性文件中 url 两边的引号 (")。通过删除报价,liquidbase运行良好.....现在脑子很痛。