db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jose de Castro <jose.decas...@voxeo.com>
Subject Re: run script from java - w/ ij
Date Wed, 27 Dec 2006 15:21:51 GMT
The Derby Tools Library(derbytools.jar) contains a class named 'ij' 
which provides a static method called 'runScript'. This is the key to 
accomplishing what you want.

NOTE: The 'runScript' method returns the number of errors that occurred 
during the execution of the script.

Here is an example method that takes in a database connection and a 
script file:

protected boolean runScript(File scriptFile, Connection connection) {
    FileInputStream fileStream = null;
    try {
        fileStream = new FileInputStream(scriptFile);
        int result  = 
        System.out.println("Result code is: " + result);
        return (result==0);
    catch (FileNotFoundException e) {
        return false;
    catch (UnsupportedEncodingException e) {
        return false;
    finally {
        if(fileStream!=null) {
            try {
            catch (IOException e) {

Hope this helps,

Jose de Castro
Senior Software Engineer
Voxeo Corporation

m96 wrote:
> hello,
> i looked in the documentation and searched the web without any luck on
> how to run an external sql script from inside a java program - this
> means without using the interactive shell ij (run
> '/path/to/script.sql';) since 'run' is an ij command only.
> i'm thinking (at least hoping) since the stored procedure
> SYSCS_UTIL.SYSCS_IMPORT_TABLE also allows to access the file system
> there should be a way to run an external script - without reading,
> parsing the file by my-self and redirecting it as sql...
> thanks in advance.
> cheers...

View raw message