MS-SQL Liquibase - 无法创建连接

时间:2018-03-01 15:49:30

标签: java sql-server jdbc liquibase

我正在尝试为数据库部署到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示例code测试了连接。我将mssql-jdbc-6.2.2.jre8.jar添加到我的项目中,并使用属性文件中相同的url,username,databaseName和password成功运行了查询。

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

1 个答案:

答案 0 :(得分:0)

我发现了问题。问题是属性文件中url周围的引号(")。通过删除引号,液体基地运行正常......现在很多大脑都受伤了。