如何运行sql脚本以便从java代码更新Derby架构? [英] How to run sql scripts in order to update a Derby schema from java code?

查看:82
本文介绍了如何运行sql脚本以便从java代码更新Derby架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们客户端的derby数据库安装具有不同的架构版本。例如。 Customer1具有db模式版本4.1.5.0240,Customer2具有版本4.0.1.0330。

The derby database installations of our customer sides have different schema versions. E.g. Customer1 has db schema version 4.1.5.0240, Customer2 has version 4.0.1.0330.

想法是在安装新软件时将这些模式更新为实际版本。存在多个sql脚本以便将版本更新到下一级别。例如。 update_4.1.5.0240_to_4.3.1.0020.sql。

The idea is to update theses schemas to actual version when a new software is installed. There exists several sql scripts in order update a version to next level. E.g. update_4.1.5.0240_to_4.3.1.0020.sql.

我正在寻找的工具/程序应该从derby数据库表中读取实际安装的版本。根据该版本,应运行适当的sql脚本,以便将架构更新到下一级别。必须重复此过程,直到找不到与实际读取版本匹配的sql脚本。

The tool/procedure I am looking for should read the actual installed version from a derby database table. According to that version the appropriate sql script shall be run in order to update the schema to next level. This procedure must be repeated until no matching sql script can be found for the actual read version.

客户站点的安装应无头,无需任何管理员帮助。

The installation at customer site should be done headless without any administrators help.

1。)我更喜欢使用JDBC读取版本的java程序。但是如何从java中运行sql脚本?我应该从java调用ij命令行工具吗?

1.) I would prefer a java program that reads the version using JDBC. But how to run the sql scripts from within java? Should I call the ij commandline tool from java?

2。)有更好的选择吗?

2.) Are there better alternatives?

谢谢
Viktor

Thanks Viktor

推荐答案

您可能会发现ij.runScript方法很有用: http://db.apache.org/derby/javadoc/publishedapi/jdbc4/org/ apache / derby / tools / ij.html

You might find the ij.runScript method helpful: http://db.apache.org/derby/javadoc/publishedapi/jdbc4/org/apache/derby/tools/ij.html

需要注意的一点是,在脚本中自动执行错误处理并不容易在ij脚本中没有控制流(if / then / else)构造。但是如果你只需要以干净的方式执行一系列DDL操作,那么ij.runScript是一种非常好的技术。

One thing to be aware of is that it's not easy to automate the error handling inside the script, as there are no control flow (if/then/else) constructs in the ij scripting. But if you just need to perform a series of DDL operations in a clean manner, ij.runScript is a pretty good technique.

这篇关于如何运行sql脚本以便从java代码更新Derby架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆