【发布时间】:2018-08-09 17:55:04
【问题描述】:
我正在尝试设置 liquibase 以将数据库部署到 MS SQL Server 2014。当我尝试运行更新(使用命令行)时,我收到以下错误消息:
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 示例 code 测试了连接。我将 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
【问题讨论】:
-
请发布完整的异常堆栈跟踪
-
@MarkRotteveel 我已经为你添加了堆栈跟踪。
-
你确定这是完整的堆栈跟踪,并且没有进一步的原因吗?
-
@MarkRotteveel 这是我使用 --logLevel debug 得到的所有输出
-
奇怪,我本以为会出现 SQLException。另一个猜测:你的 Java 8 版本太旧了,试试更新的版本(Java 8 Update 162)
标签: java sql-server jdbc liquibase