更新由 symmetricds 同步的表
Posted
技术标签:
【中文标题】更新由 symmetricds 同步的表【英文标题】:Updating a table synchronised by symmetricds 【发布时间】:2019-06-27 10:07:40 【问题描述】:我一直在做一个涉及使用对称 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 的新手
【问题讨论】:
【参考方案1】:同步 h2 数据库的应用程序的类路径上缺少 symmetricDs jar:symmetric-db-YOUR_VERSION.jar
。
【讨论】:
能否详细说明。我在存储我的 Java 文件的同一文件夹中有一个lib
文件夹,其中包含您指定的 jar 文件。我尝试使用以下命令运行我的程序 java -cp ".:./h2-1.3.176.jar" -cp ".:./lib/symmetric-db-3.10.2.jar" dataBaseManager
这里您可以检测您的程序以打印所有依赖项并确定 jar 是否已包含在类路径中:mkyong.com/java/how-to-print-out-the-current-project-classpath
我发现的一个临时解决方案是在 bin/sym 进程运行时执行该进程以上是关于更新由 symmetricds 同步的表的主要内容,如果未能解决你的问题,请参考以下文章