I'm just throwing around ideas at this point, but it would be awesome if the code from runscript could be made into a system stored procedure. Then it's always there and runscript from ij could re-use the same functionality.
Just a thought.
Jim Newsham wrote:
>> -----Original Message-----
>> From: Bryan Pendleton [mailto:firstname.lastname@example.org]
>> Sent: Thursday, May 10, 2007 9:58 AM
>> To: Derby Discussion
>> Subject: Re: Executing command from a file via JDBC
>>> I didn't want to distribute derbytools.jar with my application. I guess
>>> was looking for something that came with the core jdbc driver.
>> You could put something together yourself pretty easily:
>> BufferedReader rdr = ...;
>> String sql;
>> Statement stmt = conn.createStatement();
>> while ( (sql = rdr.readLine()) != null)
>> Would that serve your purposes?
> I had a need to run sql scripts into our database at runtime as well. I
> didn't find anything in the Derby API, so I whipped the following up. We
> use it to create the database structure from a .sql resource, the first time
> our application runs (and also within unit tests, since we want a newly
> initialized copy of the database for each test).
> It's not bullet-proof (read the comments), but it was sufficient for our
> purposes. If something like this doesn't already exist in Derby, it sure
> would be useful... with the documented deficiencies remedied, of course.
How about the runscript() method in ij?
public static int runScript(java.sql.Connection conn,
Run a SQL script from an InputStream and write the resulting output
to the provided PrintStream. SQL commands are separated by a semi-colon
conn - Connection to be used as the script's default connection.
sqlIn - InputStream for the script.
inputEncoding - Encoding of the script.
sqlOut - OutputStream for the script's output
outputEncoding - Output encoding to use.
Number of SQLExceptions thrown during the execution, -1 if not