【问题标题】:Liquibase Db2 configruationLiquibase Db2 配置
【发布时间】:2020-07-31 23:31:03
【问题描述】:

我正在尝试让 ubuntu 上的 liquibase 3.10.2 第一次与 Db2 仓库一起工作。 按照教程示例,H2“liquibase 更新”示例工作正常。

使用指定的 jars 和下面的 url 字符串,可以在 dbeaver 上正常工作,但将其转换为 liquibase 会提供以下错误。

driver: com.ibm.db2.jcc.DB2Driver 
#jars in /test1/sql
classpath: db2jcc4.jar:db2jcc_license_cu.jar
databaseClass: com.ibm.db2.jcc.DB2Driver

# Enter the path for your changelog file.
changeLogFile: samplechangelog.h2.sql

#### Enter the Target database 'url' information  ####
url: jdbc:db2://192.168.72.143:50000/bludb

# Enter the username for your Target database.
username: bluadmin

# Enter the password for your Target database.
password: bluadmin

#### Enter the Source Database 'referenceUrl' information ####
## The source database is the baseline or reference against which your target database is compared for diff/diffchangelog commands.

# Enter URL for the source database
referenceUrl: jdbc:db2://192.168.72.143:50000/bludb

# Enter the username for your source database
referenceUsername: bluadmin

# Enter the password for your source database
referencePassword: bluadmin


09:23:16.261 ERROR [liquibase.integration.commandline.Main]: Unexpected error running Liquibase: java.lang.ClassCastException: class com.ibm.db2.jcc.DB2Driver cannot be cast to class liquibase.database.Database (com.ibm.db2.jcc.DB2Driver is in unnamed module of loader java.net.URLClassLoader @242aa8d9; liquibase.database.Database is in unnamed module of loader 'app')
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.lang.ClassCastException: class com.ibm.db2.jcc.DB2Driver cannot be cast to class liquibase.database.Database (com.ibm.db2.jcc.DB2Driver is in unnamed module of loader java.net.URLClassLoader @242aa8d9; liquibase.database.Database is in unnamed module of loader 'app')
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:125)
    at liquibase.integration.commandline.Main.doMigration(Main.java:1341)
    at liquibase.integration.commandline.Main.run(Main.java:303)
    at liquibase.integration.commandline.Main.main(Main.java:159)
Caused by: liquibase.exception.DatabaseException: java.lang.ClassCastException: class com.ibm.db2.jcc.DB2Driver cannot be cast to class liquibase.database.Database (com.ibm.db2.jcc.DB2Driver is in unnamed module of loader java.net.URLClassLoader @242aa8d9; liquibase.database.Database is in unnamed module of loader 'app')
    at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:259)
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:149)
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:90)
    ... 3 common frames omitted
Caused by: java.lang.ClassCastException: class com.ibm.db2.jcc.DB2Driver cannot be cast to class liquibase.database.Database (com.ibm.db2.jcc.DB2Driver is in unnamed module of loader java.net.URLClassLoader @242aa8d9; liquibase.database.Database is in unnamed module of loader 'app')
    at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:187)
    ... 5 common frames omitted

更新的附加信息:

(1) 导致显示错误的完整命令行是什么? 我正在发布 h2 教程中引用的简单示例

jarrod@ubuntu:~/liquibase3.10.2/test1/sql$ ls -al
total 6424
drwxrwxr-x 2 jarrod jarrod    4096 Aug  1 08:50 .
drwxrwxr-x 4 jarrod jarrod    4096 Aug  1 08:50 ..
-rw-r--r-- 1 jarrod jarrod     218 Jul 14 05:49 blankchangelog.h2.sql
-r--r--r-- 1 jarrod jarrod 6550443 Jun 11  2019 db2jcc4.jar
-r--r--r-- 1 jarrod jarrod    1529 Jun 11  2019 db2jcc_license_cu.jar
-rw-r--r-- 1 jarrod jarrod    2678 Aug  1 09:23 liquibase.properties
-rw-r--r-- 1 jarrod jarrod     456 Jul 14 05:49 samplechangelog.h2.sql
jarrod@ubuntu:~/liquibase3.10.2/test1/sql$ liquibase update 
15:05:37.848 DEBUG [liquibase.resource.ClassLoaderResourceAccessor]: Opening jar:file:/home/jarrod/liquibase3.10.2/liquibase.jar!/liquibase.build.properties as liquibase.build.properties
15:05:37.868 INFO  [liquibase.integration.commandline.Main]: ####################################################
##   _     _             _ _                      ##
....

(2) 变更日志文件内容是什么 这与示例 h2 更改日志相同;没有变化。

jarrod@ubuntu:~/liquibase3.10.2/test1/sql$ cat samplechangelog.h2.sql 
--liquibase formatted sql

--changeset your.name:1
create table person (
    id int primary key,
    name varchar(50) not null,
    address1 varchar(50),
    address2 varchar(50),
    city varchar(30)
)

--changeset your.name:2
create table company (
    id int primary key,
    name varchar(50) not null,
    address1 varchar(50),
    address2 varchar(50),
    city varchar(30)
)

--changeset other.dev:3
alter table person add column country varchar(2)

jarrod@ubuntu:~/liquibase3.10.2/test1/sql$ 

(3) 您使用的是哪个 Db2 驱动程序版本?

捆绑名称:IBM JCC JDBC 4 驱动程序

(4) 什么确切的查询在 dbeaver 中有效,但在 liquibase 中失败?

目前没有,只是试图让连接正常工作。 我在 Dbeaver 中有一个工作连接,使用相同的 jdbc 驱动程序、相同的类名、相同的服务器、数据库、用户名、密码和 URL 模板。

我真的很高兴收到 SQL 错误!

【问题讨论】:

  • 请编辑您的问题以添加缺失的事实 (1) 导致显示错误的完整命令行是什么? (2) 更改日志文件的内容是什么 (3) 您使用的是哪个 Db2 驱动程序版本? (4) 什么确切的查询在 dbeaver 中有效,但在 liquibase 中失败?
  • 感谢您的关注。我已经更新了原帖。

标签: db2 liquibase


【解决方案1】:

liquibase 3.10.2 似乎适用于我的 Db2-LUW。

尝试进行这些更改,这些更改记录在文本文件 GETTING_STARTED.txt 中。

要么将 Db2 jar 文件移动到 liquibase 的 lib 子目录中,要么对 liquibase 使用的 CLASSPATH 进行更改。对于 Db2-LUW,文件是:lib/db2jcc4.jar , lib/db2jcc.jar , lib/db2jcc_license_cu.jar。您的问题表明您将这些文件复制到 liquibase 目录而不是 liquibase lib 子目录中。

Db2-LUW 将拒绝 H2 的示例 changeLogFile 中的语法,因为 Db2-LUW 要求主键列不为空。在示例文件中,您可以将所有表的 id int primary key 更改为 id int not null primary key,以避免 SQLCODE -542。

【讨论】:

  • 谢谢。我将 jar 移动到 /lib 并从属性文件中删除了类的东西。可能有点超前了!再次感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-18
  • 1970-01-01
  • 2016-07-02
  • 1970-01-01
  • 2017-09-06
  • 2016-02-12
  • 1970-01-01
相关资源
最近更新 更多