Search code examples
unixjdbcderbyksh

How to execute an SQL script for Derby DB from a ksh script


I am trying to write a small program that utilizes a sql script I wrote, to access data within a Derby DB (let's call it "myscript.sql") from within a ksh script.

I seem to be running into problems however since my ksh script can only launch the "ij" tool, and is not able to input any further commands in the ij shell once opened (thus, can not connect to the DB).

Is there any way that the ksh script can echo commands to the ij shell, so I can connect/execute my query as needed ?


Solution

  • You can accomplish this by redirecting stdin to the ij tool and running it using java:

    Name an input file as a command-line argument. For example:

    java org.apache.derby.tools.ij myscript.sql

    Redirect standard input to come from a file. For example:

    java org.apache.derby.tools.ij < myscript.sql

    Source: Derby documentation