gpt4 book ai didi

java - 更新由 symmetricds 同步的表

转载 作者:行者123 更新时间:2023-11-30 21:30:03 25 4
gpt4 key购买 nike

我一直在从事一个涉及使用对称 ds 同步两个数据库的小项目。我的数据库之一是 mysql,另一个是 h2。我希望我的程序在单击时更新 h2 数据库。但是,更新函数会生成类似以下内容的错误:

org.h2.jdbc.JdbcSQLException: Error creating or initializing trigger 
"SYM_ON_I_FOR_DBTRGGR_CRS_LCL" object, class "org.jumpmind.symmetric.db.h2.H2Trigger", cause: "org.h2.message.DbException: Class ""org.jumpmind.symmetric.db.h2.H2Trigger"" not found [90086-176]"; see root cause for details; SQL statement:
INSERT INTO passenger VALUES(1, 'Person1', 20, 'City1', 'City2', 1); [90043-176]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.schema.TriggerObject.load(TriggerObject.java:77)
at org.h2.schema.TriggerObject.fireRow(TriggerObject.java:167)
at org.h2.table.Table.fireRow(Table.java:935)
at org.h2.table.Table.fireAfterRow(Table.java:925)
at org.h2.command.dml.Insert.insertRows(Insert.java:162)
at org.h2.command.dml.Insert.update(Insert.java:115)
at org.h2.command.CommandContainer.update(CommandContainer.java:79)
at org.h2.command.Command.executeUpdate(Command.java:254)
at

org.h2.jdbc.JdbcStatement.executeUpdateInternal(JdbcStatement.java:132)
at org.h2.jdbc.JdbcStatement.executeUpdate(JdbcStatement.java:117)
at h2Connector.UpdateLocalDB(dataBaseManager.java:105)
at h2Connector.<init>(dataBaseManager.java:34)
at dataBaseManager.main(dataBaseManager.java:8)
Caused by: org.h2.message.DbException: Class "org.jumpmind.symmetric.db.h2.H2Trigger" not found [90086-176]
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.util.Utils.loadUserClass(Utils.java:672)
at org.h2.schema.TriggerObject.load(TriggerObject.java:70)
... 12 more
Caused by: org.h2.jdbc.JdbcSQLException: Class "org.jumpmind.symmetric.db.h2.H2Trigger" not found [90086-176]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
... 15 more
Caused by: java.lang.ClassNotFoundException: org.jumpmind.symmetric.db.h2.H2Trigger
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.h2.util.Utils.loadUserClass(Utils.java:665)
... 13 more

我看到了类似的帖子 https://sourceforge.net/p/symmetricds/discussion/739236/thread/8a54e2ec/其中指出“从 SymmetricDS 主目录尝试此操作。H2 数据库需要用于 java 触发器的 SymmetricDS 库。”并引导使用命令

java -cp web/WEB-INF/lib/*:lib/h2-1.3.176.jar org.h2.tools.Console

我尝试使用它来运行我的代码,但遗憾的是无法弄明白。

这是我的 h2(本地端)属性文件:

engine.name=CRIS_Local-01
db.driver=org.h2.Driver
db.url=jdbc:h2:CRISDB;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000
db.user=sa
db.password=
registration.url=http://localhost:31415/sync/CRIS_Server-00
group.id=CRIS_Local
external.id=01
job.routing.period.time.ms=5000
job.push.period.time.ms=1000
job.pull.period.time.ms=1000

这是我的 mysql(服务器端)属性文件:

engine.name=CRIS_Server-00
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost/PassDB?tinyInt1isBit=false
db.user=root
db.password=passwd
registration.url=
sync.url=http://localhost:31415/sync/CRIS_Server-00
group.id=CRIS_Server
external.id=00
job.purge.period.time.ms=7200000
job.routing.period.time.ms=5000
job.push.period.time.ms=1000
job.pull.period.time.ms=1000
auto.registration=true
initial.load.create.first=true

这是我建立连接的java代码:

h2Connector(){
stmt = null;
con = null;
try{
Class.forName("org.h2.Driver");
con = DriverManager.getConnection("jdbc:h2:~/Downloads/symmetric-server-3.10.2/tmp/h2/CRISDB;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000", "sa","");
stmt = con.createStatement();
System.out.println("Connected to h2 Succesfully!");
}catch(Exception e){
e.printStackTrace();
}
Passenger psg = GivePassenger(1,isOccupied);
System.out.println(psg.Name);
UpdateLocalDB(psg);
}

这是我的 UpdateLocalDB(Passenger psg)

public void UpdateLocalDB(Passenger psg){
String query = "";
query = "INSERT INTO passenger VALUES(";
query += Integer.toString(psg.PNRNo) + ", ";
query += "'"+psg.Name+"', ";
query += Integer.toString(psg.age)+", ";
query += "'"+psg.start+"', ";
query += "'"+psg.end+"', ";
query += Integer.toString(psg.seat) + ");";
System.out.println(query);

try{
stmt.executeUpdate(query);
System.out.println("Updated Succesfully!");
}
catch(Exception e){
e.printStackTrace();
}
}

查询部分工作正常PS:我是 SymmetricDS 的新手

最佳答案

同步 h2 数据库的应用程序的类路径上缺少 symmetricDs jar:symmetric-db-YOUR_VERSION.jar

关于java - 更新由 symmetricds 同步的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56788714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com