snaq.db
Class SQLUpdate

java.lang.Object
  extended by snaq.db.SQLUpdate

public class SQLUpdate
extends Object

Command-line utility to send SQL commands to a database. This class is useful for creating a large number of database tables and/or records from a user-defined text file containing SQL commands. It relies on the ConnectionPoolManager class to assist with the creation of a connection to the database, which in turn requires the appropriate dbpool.properties file in the classpath.

     Usage: java snaq.db.SQLUpdate <poolnames> <input file> [<separator>]
 
where pool is the name of the connection pool as defined in the dbpool.properties file, input file is the name of the text file containing the SQL statements to be issued to the defined database, and separator is an optional parameter to specify a delimiter for the SQL statements in the file. If the separator is not specified then each line of the file is assumed to be a separate statement.

Note: comments are allowed in the input file by starting the line with either "#" or "--".

Author:
Giles Winstanley
See Also:
ConnectionPoolManager

Constructor Summary
SQLUpdate(String db)
           
 
Method Summary
static String loadTextFile(File f)
          Loads a text file into a string.
static void main(String[] args)
          Allows command-line issuing of SQL statements to a database defined in the pool manager properties file.
static String[] splitSQL(String text, String separator)
          Splits the specified text input into separate SQL statements.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLUpdate

public SQLUpdate(String db)
          throws IOException
Throws:
IOException
Method Detail

loadTextFile

public static String loadTextFile(File f)
                           throws IOException
Loads a text file into a string.

Parameters:
f - File containing text to load
Returns:
String containing the text loaded from the specified file
Throws:
IOException

splitSQL

public static String[] splitSQL(String text,
                                String separator)
Splits the specified text input into separate SQL statements.

Parameters:
text - string containing the text to be processed
separator - string specifying the separator between SQL statements
Returns:
String array containing the SQL statements parsed

main

public static void main(String[] args)
Allows command-line issuing of SQL statements to a database defined in the pool manager properties file.