org.gusdb.wdk.model.implementation
Class SqlUtils

java.lang.Object
  extended by org.gusdb.wdk.model.implementation.SqlUtils

public class SqlUtils
extends java.lang.Object


Constructor Summary
SqlUtils()
           
 
Method Summary
static void closeResultSet(java.sql.ResultSet resultSet)
           
static void closeStatement(java.sql.Statement stmt)
           
static boolean execute(javax.sql.DataSource dataSource, java.lang.String sql)
          Execute an SQL statement
static int executeUpdate(javax.sql.DataSource dataSource, java.lang.String sql)
          Perform a JDBC insert/update/delete.
static java.lang.String[] getColumnNames(javax.sql.DataSource dataSource, java.lang.String sql)
           
static java.sql.PreparedStatement getPreparedStatement(javax.sql.DataSource dataSource, java.lang.String sql)
           
static int getResultSet(javax.sql.DataSource dataSource, java.sql.PreparedStatement prepStmt)
          Gets a result set using a PreparedStatement.
static java.sql.ResultSet getResultSet(javax.sql.DataSource dataSource, java.lang.String sql)
           
static void printResultSet(java.sql.ResultSet rs)
           
static java.lang.Integer runIntegerQuery(javax.sql.DataSource dataSource, java.lang.String sql)
          Execute a JDBC query that returns a single Integer and return the Integer.
static java.lang.String[] runStringArrayQuery(javax.sql.DataSource dataSource, java.lang.String sql)
          Execute a JDBC query that returns a list of strings, and return the strings in an array.
static java.lang.String runStringQuery(javax.sql.DataSource dataSource, java.lang.String sql)
          Execute a JDBC query that returns a single string (and return the string!)
static void writeResultSet(java.sql.ResultSet rs, java.lang.StringBuffer buf)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlUtils

public SqlUtils()
Method Detail

getResultSet

public static java.sql.ResultSet getResultSet(javax.sql.DataSource dataSource,
                                              java.lang.String sql)
                                       throws java.sql.SQLException
Throws:
java.sql.SQLException

getResultSet

public static int getResultSet(javax.sql.DataSource dataSource,
                               java.sql.PreparedStatement prepStmt)
                        throws java.sql.SQLException
Gets a result set using a PreparedStatement. Since the statement is prepared, it is likely that the user is intending to use it more than once before closing it. It is thus up to the user to close the PreparedStatement using closeStatement when finished.

Throws:
java.sql.SQLException

getPreparedStatement

public static java.sql.PreparedStatement getPreparedStatement(javax.sql.DataSource dataSource,
                                                              java.lang.String sql)
                                                       throws java.sql.SQLException
Throws:
java.sql.SQLException

closeResultSet

public static void closeResultSet(java.sql.ResultSet resultSet)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

closeStatement

public static void closeStatement(java.sql.Statement stmt)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

runStringQuery

public static java.lang.String runStringQuery(javax.sql.DataSource dataSource,
                                              java.lang.String sql)
                                       throws java.sql.SQLException
Execute a JDBC query that returns a single string (and return the string!)

Throws:
java.sql.SQLException

runIntegerQuery

public static java.lang.Integer runIntegerQuery(javax.sql.DataSource dataSource,
                                                java.lang.String sql)
                                         throws java.sql.SQLException
Execute a JDBC query that returns a single Integer and return the Integer.

Throws:
java.sql.SQLException

runStringArrayQuery

public static java.lang.String[] runStringArrayQuery(javax.sql.DataSource dataSource,
                                                     java.lang.String sql)
                                              throws java.sql.SQLException
Execute a JDBC query that returns a list of strings, and return the strings in an array.

Throws:
java.sql.SQLException

getColumnNames

public static java.lang.String[] getColumnNames(javax.sql.DataSource dataSource,
                                                java.lang.String sql)
                                         throws java.sql.SQLException
Returns:
the list of column names from the select statement
Throws:
java.sql.SQLException

executeUpdate

public static int executeUpdate(javax.sql.DataSource dataSource,
                                java.lang.String sql)
                         throws java.sql.SQLException
Perform a JDBC insert/update/delete.

Returns:
The number of rows affected.
Throws:
java.sql.SQLException

execute

public static boolean execute(javax.sql.DataSource dataSource,
                              java.lang.String sql)
                       throws java.sql.SQLException
Execute an SQL statement

Returns:
Value as described in java.sql.statement.execute()
Throws:
java.sql.SQLException

printResultSet

public static void printResultSet(java.sql.ResultSet rs)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

writeResultSet

public static void writeResultSet(java.sql.ResultSet rs,
                                  java.lang.StringBuffer buf)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException