net.walend.jdbc
Class SQLUtils

java.lang.Object
  |
  +--net.walend.jdbc.SQLUtils

public class SQLUtils
extends java.lang.Object

A kit of utilities for working with databases.

Since:
20001127
Author:
David Walend

Constructor Summary
SQLUtils()
           
 
Method Summary
static void cleanUp(java.sql.Connection connection, java.sql.Statement statement, java.sql.ResultSet resultSet)
          Close down the resultSet, statement and connection safely.
static int executeCountQuery(java.lang.String databaseName, java.lang.String sql)
          Return the number of rows found by a select statement.
static boolean executeIsPresentQuery(java.lang.String databaseName, java.lang.String sql)
          Execute a query that expects zero or one rows.
static long executeNumberQuery(java.lang.String databaseName, java.lang.String sql)
          Run a select query that returns a single long value
static SelectTuple executeQuery(java.lang.String databaseName, java.lang.String sql)
          Run a query that returns a resultSet and generate the needed SelectTupple to close it safely.
static java.util.Iterator executeQueryForIteratorOfLongs(java.lang.String databaseName, java.lang.String sql)
          Return an Iterator of Longs found by a select query.
static Set executeQueryForSetOfIntegers(java.lang.String databaseName, java.lang.String sql)
          Return a set of integers found by a select query.
static Set executeQueryForSetOfLongs(java.lang.String databaseName, java.lang.String sql)
          Return a Set of Longs found by a select query.
static Set executeQueryForSetOfStrings(java.lang.String databaseName, java.lang.String sql)
          Return a Set of Strings found by a select query.
static java.lang.String executeStringQuery(java.lang.String databaseName, java.lang.String sql)
          Run a select query that returns a single long value
static int executeUpdate(java.lang.String databaseName, java.lang.String sql)
          Execute an sql statement.
static void executeUpdate(java.lang.String databaseName, java.lang.String sql, int expectedResult)
          Execute an sql statement.
private static PropertySource getPropertySource()
           
private static boolean useGetUpdateCount()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLUtils

public SQLUtils()
Method Detail

getPropertySource

private static PropertySource getPropertySource()

useGetUpdateCount

private static boolean useGetUpdateCount()

executeUpdate

public static int executeUpdate(java.lang.String databaseName,
                                java.lang.String sql)
                         throws java.sql.SQLException
Execute an sql statement.

Returns:
the number of rows changed

executeUpdate

public static void executeUpdate(java.lang.String databaseName,
                                 java.lang.String sql,
                                 int expectedResult)
                          throws java.sql.SQLException
Execute an sql statement.

Throws:
java.sql.SQLException - If the result does not match the expected result, or anything else goes wrong.

executeQuery

public static SelectTuple executeQuery(java.lang.String databaseName,
                                       java.lang.String sql)
                                throws java.sql.SQLException
Run a query that returns a resultSet and generate the needed SelectTupple to close it safely.


executeQueryForIteratorOfLongs

public static java.util.Iterator executeQueryForIteratorOfLongs(java.lang.String databaseName,
                                                                java.lang.String sql)
                                                         throws java.sql.SQLException
Return an Iterator of Longs found by a select query.


executeQueryForSetOfLongs

public static Set executeQueryForSetOfLongs(java.lang.String databaseName,
                                            java.lang.String sql)
                                     throws java.sql.SQLException
Return a Set of Longs found by a select query.


executeQueryForSetOfIntegers

public static Set executeQueryForSetOfIntegers(java.lang.String databaseName,
                                               java.lang.String sql)
                                        throws java.sql.SQLException
Return a set of integers found by a select query.


executeQueryForSetOfStrings

public static Set executeQueryForSetOfStrings(java.lang.String databaseName,
                                              java.lang.String sql)
                                       throws java.sql.SQLException
Return a Set of Strings found by a select query.


executeNumberQuery

public static long executeNumberQuery(java.lang.String databaseName,
                                      java.lang.String sql)
                               throws java.sql.SQLException
Run a select query that returns a single long value


executeStringQuery

public static java.lang.String executeStringQuery(java.lang.String databaseName,
                                                  java.lang.String sql)
                                           throws java.sql.SQLException
Run a select query that returns a single long value


executeCountQuery

public static int executeCountQuery(java.lang.String databaseName,
                                    java.lang.String sql)
                             throws java.sql.SQLException
Return the number of rows found by a select statement.


executeIsPresentQuery

public static boolean executeIsPresentQuery(java.lang.String databaseName,
                                            java.lang.String sql)
                                     throws java.sql.SQLException
Execute a query that expects zero or one rows.


cleanUp

public static void cleanUp(java.sql.Connection connection,
                           java.sql.Statement statement,
                           java.sql.ResultSet resultSet)
Close down the resultSet, statement and connection safely. Use this method in finally blocks after queries. SelectTuple uses this method inside its own close() method.



Copyright (c) 2000, 2001, David Walend