db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stanley Bradbury <Stan.Bradb...@gmail.com>
Subject Re: run script from java - w/ ij
Date Thu, 28 Dec 2006 21:08:32 GMT
Hi -
The Javadoc documents this and other useful API calls - info on the IJ 
class is at:

http://db.apache.org/derby/docs/10.2/publishedapi/org/apache/derby/tools/ij.html

Jose de Castro wrote:
> 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  = 
> ij.runScript(connection,fileStream,"UTF-8",System.out,"UTF-8");
>        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 {
>                fileStream.close();
>            }
>            catch (IOException e) {
>            }
>        }
>    }
> }
>
> Hope this helps,
>
> Jose de Castro
> Senior Software Engineer
> Voxeo Corporation
> jose.decastro@voxeo.com
>
>
> 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...
>>
>>   
>



Mime
View raw message