net.spy.db
Class SQLRunner

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.db.SQLRunner

public class SQLRunner
extends SpyObject

Run a SQL script from an InputStream.

SQL scripts run by this class are slightly special over normal SQL scripts in that they require a particular structure.

Lines beginning with a SQL comment (--) are logged at info level. Queries are executed when a semicolon is encountered on a line all by itself. Empty lines are ignored. Everything else is concatenated to form the next query to execute. Queries that return a result set will throw a SQLException.


Constructor Summary
SQLRunner(java.sql.Connection conn)
          Get an instance of SQLRunner.
 
Method Summary
 void runScript(java.io.InputStream is)
          Run the given script as a transaction.
 void runScript(java.io.InputStream is, boolean autocommit, boolean errok)
          Run the given script.
 void setTimeout(int to)
          Set the query timeout (in seconds).
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLRunner

public SQLRunner(java.sql.Connection conn)
Get an instance of SQLRunner.

Method Detail

setTimeout

public void setTimeout(int to)
Set the query timeout (in seconds).


runScript

public void runScript(java.io.InputStream is)
               throws java.sql.SQLException,
                      java.io.IOException
Run the given script as a transaction.

Parameters:
is - the stream containing the script
Throws:
java.sql.SQLException - if there's a SQL problem with this script
java.io.IOException - if there's a problem reading the script

runScript

public void runScript(java.io.InputStream is,
                      boolean autocommit,
                      boolean errok)
               throws java.sql.SQLException,
                      java.io.IOException
Run the given script.

Parameters:
is - the stream containing the script
autocommit - if true, commit after each statement
errok - if true, ignore SQL exceptions on each statement
Throws:
java.sql.SQLException - if there's a SQL problem executing the script
java.io.IOException - if there's a problem reading the script


Copyright © 1995-2006 SPY Internetworking. All Rights Reserved.