MySQL触发器或存储过程可以用Java编写吗?
我有两个数据库。对其中一个的编辑、插入等更改也需要对第二个进行,反之亦然。
实际上,一个数据库是一个旧的遗留数据库(具有非常糟糕的实体关系结构)和用户当前使用的遗留应用程序前端。 第二个数据库是新建的,通过单独的应用程序对遗留数据库进行了更好的重组。前端。
我希望两个应用程序(分别访问旧数据库和新数据库)同时运行,以便用户可以选择使用这两个应用程序,并且一个应用程序中的更改在另一个应用程序中可见。
我想编写调用存储过程的触发器,该存储过程重组数据并将其放入相反的数据库中。
我的问题是:
- 我的执行路线是否符合预期?我的意思是,
触发 >call>存储过程>调用>数据库。
- 触发器/存储过程可以用Java 编写吗?
- 有什么好的/推荐的技巧、教程等吗?
谷歌上有很多链接,但没有一个有用。我想知道MySQL和Java在MySQL触发器方面是否可以一起工作?可能吗?有更好的方法来实现我的需要吗?
I have two databases. Changes like edits, insertions to one, need to be made to the second one as well and vice versa.
Actually, one database is an old legacy database (with a very bad Entity-Relationship structure) and a legacy app front-end currently used by users.
The second database is a newly built, better restructure of the legacy with a separate app. front-end.
I want both apps (accessing the legacy and the new database respectively) to run simultaneously so users can have the option to use both applications and changes in one app are visible across the other.
I want to write triggers which call stored procedures, which restructure the data and put it in the opposite database.
My question is:
- Is my line of execution as it is supposed to be? I mean,
triggers >call> stored procedures >call> database.
- Can triggers / stored procedures be written in Java?
- Any good/ recommended tips, tutorials etc etc out there?
There are many links on google but none of them are useful. I wonder if MySQL and Java work together when it comes to MySQL triggers? is it possible or not?. Is there a better way of achieving what I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
触发器是命名的数据库对象。它们定义了当某些数据库相关事件发生时数据库应采取的一些操作。它们是用 SQL 编写的。它们的执行对用户来说是透明的。您像往常一样编写 Java JDBC 代码,DBMS 将在必要时自动执行适当的触发器。
这个示例向您展示了如何使触发器写入另一个数据库。小心自动增量属性。
我认为您应该忘记 MySQL 中的 Java 存储过程,但您始终可以将业务逻辑转移到您自己的 Java 程序中。
Triggers are named database objects. They define some action that the database should take when certain database related events occur. They are written in SQL. Their execution is transparent to the user. You write your Java JDBC code as usual and the DBMS will automatically execute the appropriate trigger whenever necessary.
This example shows you how to make your trigger write to another database. Be careful with auto-increment attributes.
I think you should forget about Java stored procedures in MySQL, but you could always move the business logic to your own Java program.