Class JDBCScriptTool


  • public class JDBCScriptTool
    extends java.lang.Object
    A tool that reads an input SQL script and output information for the result either to an output file or through System.out. This is a useful command line tool that can be used for regression testing and database diagnostics (as well as for basic SQL scripting needs).

    This class is able to output result sets in textual form.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.Reader in
      The Reader we are reading the script commands from.
      private java.io.PrintWriter out
      The Writer we are outputing the script results to.
    • Constructor Summary

      Constructors 
      Constructor Description
      JDBCScriptTool​(java.io.Reader input, java.io.PrintWriter output)
      Constructs the tool.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.sql.Connection[] evaluate​(java.sql.Connection connection, java.lang.String url, java.lang.String username, java.lang.String password)
      Evaluates the input script and outputs the result to the output stream.
      static void main​(java.lang.String[] args)
      The application start point.
      private java.lang.String nextQuery()
      Fetches the next query from the input.
      private static void printSyntax()
      Prints the syntax to System.out.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • in

        private java.io.Reader in
        The Reader we are reading the script commands from.
      • out

        private java.io.PrintWriter out
        The Writer we are outputing the script results to.
    • Constructor Detail

      • JDBCScriptTool

        public JDBCScriptTool​(java.io.Reader input,
                              java.io.PrintWriter output)
        Constructs the tool.
    • Method Detail

      • nextQuery

        private java.lang.String nextQuery()
                                    throws java.io.IOException
        Fetches the next query from the input. Returns null if no more queries available.
        Throws:
        java.io.IOException
      • evaluate

        public java.sql.Connection[] evaluate​(java.sql.Connection connection,
                                              java.lang.String url,
                                              java.lang.String username,
                                              java.lang.String password)
                                       throws java.io.IOException
        Evaluates the input script and outputs the result to the output stream. Returns the list of Connections established.
        Throws:
        java.io.IOException
      • printSyntax

        private static void printSyntax()
        Prints the syntax to System.out.
      • main

        public static void main​(java.lang.String[] args)
        The application start point.