db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Newsham" <jnews...@referentia.com>
Subject RE: Executing command from a file via JDBC
Date Tue, 15 May 2007 03:59:24 GMT

Yes something like that. ;)  However, I would expect such a method to throw
an exception the first time an error occurs.  I don't see the purpose of
blindly continuing in the face of errors.  

It was some time ago, so I don't recall if I didn't use this method because
it didn't exist at the time, or I didn't know it existed, or perhaps because
it doesn't quit when an error occurs.

Thanks for the pointer,
Jim
 
> -----Original Message-----
> From: Daniel John Debrunner [mailto:djd@apache.org]
> Sent: Monday, May 14, 2007 5:42 PM
> To: Derby Discussion
> Subject: Re: Executing command from a file via JDBC
> 
> Jim Newsham wrote:
> >
> >> -----Original Message-----
> >> From: Bryan Pendleton [mailto:bpendleton@amberpoint.com]
> >> 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)
> >>       stmt.executeUpdate(sql);
> >>
> >> Would that serve your purposes?
> >>
> >> thanks,
> >>
> >> bryan
> >>
> >
> >
> > 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?
> 
> runScript
> 
> public static int runScript(java.sql.Connection conn,
>                              java.io.InputStream sqlIn,
>                              java.lang.String inputEncoding,
>                              java.io.OutputStream sqlOut,
>                              java.lang.String outputEncoding)
>                       throws java.io.UnsupportedEncodingException
> 
>      Run a SQL script from an InputStream and write the resulting output
> to the provided PrintStream. SQL commands are separated by a semi-colon
> ';' character.
> 
>      Parameters:
>          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.
>      Returns:
>          Number of SQLExceptions thrown during the execution, -1 if not
> known.
>      Throws:
>          java.io.UnsupportedEncodingException
> 
> Dan.
> 




Mime
View raw message