db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Burlison <Alan.Burli...@sun.com>
Subject Re: How to run Scripts from JDBC?
Date Mon, 03 Sep 2007 09:12:04 GMT
Néstor Boscán wrote:

> I have an application that needs to autoinstall and autoupgrade without user
> intervention. I wanted to know if I can put the scripts in a JAR file and
> run a command in derby that will run it.

Include derbytools.jar in your classpath then use something like the 
following, where /sql/myscript.sql is the location of the SQL script in 
your JAR file:

String enc = System.getProperty("file.encoding");
InputStream sql = new 
BufferedInputStream(MyClass.class.getResourceAsStream("/sql/myscript.sql"));
if (ij.runScript(db, sql, enc, System.out, enc) != 0) {
     throw new Exception("Database script failed");
}
sql.close();

-- 
Alan Burlison
--

Mime
View raw message