How to run sql scripts to update Derby schema from java code?

The derby database installations of our customers have different versions of the schemes. For instance. Client1 has a db-scheme version 4.1.5.0240, Customer2 has a version 4.0.1.0330.

The idea is to upgrade your abstract outline to the actual version when installing new software. There are several sql scripts to upgrade to the next level. For instance. update_4.1.5.0240_to_4.3.1.0020.sql.

The tool / procedure I'm looking for should read the actual installed version from the derby database table. According to this version, the corresponding sql script must be run in order to update the scheme to the next level. This procedure should be repeated until a suitable sql script is found for the real version to read.

Installation on a client site should be done without a head without the help of an administrator.

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

2.) Are there any better alternatives?

Thanks Victor

+1
source share
2 answers

ij.runScript: http://db.apache.org/derby/javadoc/publishedapi/jdbc4/org/apache/derby/tools/ij.html

, , , script , ij (/then/else). DDL , ij.runScript - .

+1

SQL :

Java, SQL / :

Java- , " SQL ".

- ( )

Installed = getCurrentInstalledVersion();//info stored in an admin table for current version

if (Installed < V4.1){//This would probably work better as a switch
String sql = updateWith(URL file:\\PathTov4.1\sql.txt);
}
else{
     if(Installed = OtherVersions){
      String sql = UpdateWith(URL file:\\PathToOtherVersion\sql.txt);
      }
}

Connect.sendSQL(sql);//send the sql to the DB

. , .

, , , break;

0

All Articles