com.waveset.util
Class JdbcUtil

java.lang.Object
  extended bycom.waveset.util.JdbcUtil

public class JdbcUtil
extends java.lang.Object

Various JDBC utilities.


Field Summary
static java.lang.String ARG_ARG1
           
static java.lang.String ARG_ARG2
           
static java.lang.String ARG_ARG3
           
static java.lang.String ARG_DATABASE
           
static java.lang.String ARG_DRIVER_CLASS
           
static java.lang.String ARG_DRIVER_PREFIX
           
static java.lang.String ARG_HOST
           
static java.lang.String ARG_PARAMS
           
static java.lang.String ARG_PASSWORD
           
static java.lang.String ARG_PORT
           
static java.lang.String ARG_SQL
           
static java.lang.String ARG_TYPE
           
static java.lang.String ARG_URL
           
static java.lang.String ARG_USER
           
static java.lang.String code_id
           
static java.lang.String ORACLE_DRIVER
           
static java.lang.String ORACLE_PREFIX
           
static java.lang.String ORACLE_URL
           
static java.lang.String TYPE_ORACLE
           
 
Constructor Summary
JdbcUtil()
           
 
Method Summary
static void closeConnection(java.sql.Connection con)
          Close a connection quietly.
static void closeResult(java.sql.ResultSet res)
          Close a result, quietly.
static void closeStatement(java.sql.PreparedStatement stmt)
          Close a statement quietly.
static void dumpArguments(java.lang.String method, java.util.Map map)
           
static java.lang.String formatUrl(java.lang.String template, java.lang.String host, java.lang.String port, java.lang.String database)
          Given a URL template and arguments, format a template.
static java.sql.Connection getConnection(java.util.Map args)
          Establish a connection.
static javax.sql.DataSource getDataSourceObject(java.lang.String factoryClass, java.lang.String path)
          Retrieves a JDBC 2.0 DataSource using JNDI.
static javax.sql.DataSource getDataSourceObject(java.lang.String factoryClass, java.lang.String path, java.util.Properties props)
          Retrieves a JDBC 2.0 DataSource using JNDI.
static javax.sql.DataSource getDataSourceObject(java.lang.String factoryClass, java.lang.String path, java.lang.String providerUrl)
          Retrieves a JDBC 2.0 DataSource using JNDI.
static java.sql.Clob parameterizedQueryClob(java.sql.Connection c, java.lang.String q, java.util.List params)
          Run a query and return the value of the first column in the first result row as a Clob.
static java.lang.String parameterizedQueryClobString(java.sql.Connection c, java.lang.String q, java.util.List params)
          Run a query and return the value of the first (Clob) column in the first result row as a String.
static java.util.Date parameterizedQueryDate(java.sql.Connection c, java.lang.String q, java.util.List params)
          Run a query and return the value of the first column in the first result row as a Date.
static int parameterizedQueryInt(java.sql.Connection c, java.lang.String q, java.util.List params)
          Run a query and return the value of the first column in the first result row as an int.
static java.util.List parameterizedQueryList(java.sql.Connection c, java.lang.String q, java.util.List params)
          Run a query and return a List of the first columns in each row.
static java.util.List parameterizedQueryRecords(java.sql.Connection c, java.lang.String q, java.util.List params)
          Run a query and return a List of Maps containing the data for each matching row.
static java.lang.String parameterizedQueryString(java.sql.Connection c, java.lang.String q, java.util.List params)
          Run a query and return the value of the first column in the first result row as a String.
static void parameterizedSql(java.sql.Connection c, java.lang.String stmt, java.util.List params)
          Run specified SQL without obtaining a result.
static int parameterizedUpdate(java.sql.Connection c, java.lang.String stmt, java.util.List params)
          Run specified DML, returning number of affected rows.
static java.sql.Clob queryClob(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return the value of the first column in the first result row as a Clob.
static java.sql.Clob queryClob(java.util.Map args)
          Run a query and return the value of the first column in the first result row as a Clob.
static java.lang.String queryClobString(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return the value of the first (Clob) column in the first result row as a String.
static java.lang.String queryClobString(java.util.Map args)
          Run a query and return the value of the first (Clob) column in the first result row as a String.
static java.util.Date queryDate(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return the value of the first column in the first result row as a Date.
static java.util.Date queryDate(java.util.Map args)
          Run a query and return the value of the first column in the first result row as a Date.
static int queryInt(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return the value of the first column in the first result row as an int.
static int queryInt(java.util.Map args)
          Run a query and return the value of the first column in the first result row as an int.
static java.util.List queryList(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return a List of the first columns in each row.
static java.util.List queryList(java.util.Map args)
          Run a query and return a List of the first columns in each row.
static java.util.List queryRecords(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return a List of Maps containing the data for each matching row.
static java.util.List queryRecords(java.util.Map args)
          Run a query and return a List of Maps containing the data for each matching row.
static java.lang.String queryString(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return the value of the first column in the first result row as a String.
static java.lang.String queryString(java.util.Map args)
          Run a query and return the value of the first column in the first result row as a String.
static void sql(java.sql.Connection c, java.lang.String stmt, java.lang.String arg)
          Run specified SQL without obtaining a result.
static void sql(java.util.Map args)
          Run specified SQL without obtaining a result.
static void sqlStream(java.sql.Connection c, java.lang.String stmt, java.io.InputStream arg, int len)
           
static int update(java.sql.Connection c, java.lang.String stmt, java.lang.String arg)
          Run specified DML, returning number of affected rows.
static int update(java.util.Map args)
          Run specified DML, returning number of affected rows.
static int update(java.sql.PreparedStatement s)
           
static int updateLong(java.sql.Connection c, java.lang.String stmt, java.lang.String arg)
          Some drivers have a limit on the size of the string that can be passed to setString(), the older Oracle driver we use has a limit of 2000.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

ARG_TYPE

public static final java.lang.String ARG_TYPE
See Also:
Constant Field Values

ARG_DRIVER_CLASS

public static final java.lang.String ARG_DRIVER_CLASS
See Also:
Constant Field Values

ARG_DRIVER_PREFIX

public static final java.lang.String ARG_DRIVER_PREFIX
See Also:
Constant Field Values

ARG_URL

public static final java.lang.String ARG_URL
See Also:
Constant Field Values

ARG_HOST

public static final java.lang.String ARG_HOST
See Also:
Constant Field Values

ARG_PORT

public static final java.lang.String ARG_PORT
See Also:
Constant Field Values

ARG_DATABASE

public static final java.lang.String ARG_DATABASE
See Also:
Constant Field Values

ARG_USER

public static final java.lang.String ARG_USER
See Also:
Constant Field Values

ARG_PASSWORD

public static final java.lang.String ARG_PASSWORD
See Also:
Constant Field Values

ARG_SQL

public static final java.lang.String ARG_SQL
See Also:
Constant Field Values

ARG_ARG1

public static final java.lang.String ARG_ARG1
See Also:
Constant Field Values

ARG_ARG2

public static final java.lang.String ARG_ARG2
See Also:
Constant Field Values

ARG_ARG3

public static final java.lang.String ARG_ARG3
See Also:
Constant Field Values

ARG_PARAMS

public static final java.lang.String ARG_PARAMS
See Also:
Constant Field Values

TYPE_ORACLE

public static final java.lang.String TYPE_ORACLE
See Also:
Constant Field Values

ORACLE_DRIVER

public static final java.lang.String ORACLE_DRIVER
See Also:
Constant Field Values

ORACLE_PREFIX

public static final java.lang.String ORACLE_PREFIX
See Also:
Constant Field Values

ORACLE_URL

public static final java.lang.String ORACLE_URL
See Also:
Constant Field Values
Constructor Detail

JdbcUtil

public JdbcUtil()
Method Detail

sql

public static void sql(java.sql.Connection c,
                       java.lang.String stmt,
                       java.lang.String arg)
                throws WavesetException
Run specified SQL without obtaining a result.

Throws:
WavesetException

parameterizedSql

public static void parameterizedSql(java.sql.Connection c,
                                    java.lang.String stmt,
                                    java.util.List params)
                             throws WavesetException
Run specified SQL without obtaining a result.

Throws:
WavesetException

update

public static int update(java.sql.Connection c,
                         java.lang.String stmt,
                         java.lang.String arg)
                  throws WavesetException
Run specified DML, returning number of affected rows.

Throws:
WavesetException

parameterizedUpdate

public static int parameterizedUpdate(java.sql.Connection c,
                                      java.lang.String stmt,
                                      java.util.List params)
                               throws WavesetException
Run specified DML, returning number of affected rows.

Throws:
WavesetException

updateLong

public static int updateLong(java.sql.Connection c,
                             java.lang.String stmt,
                             java.lang.String arg)
                      throws WavesetException
Some drivers have a limit on the size of the string that can be passed to setString(), the older Oracle driver we use has a limit of 2000. This method will use setAsciiStream instead. Could do this automatically in the update() method above, but lots of other code uses that and I'm not sure what the consequences will be - jsl

Throws:
WavesetException

update

public static int update(java.sql.PreparedStatement s)
                  throws WavesetException
Throws:
WavesetException

sqlStream

public static void sqlStream(java.sql.Connection c,
                             java.lang.String stmt,
                             java.io.InputStream arg,
                             int len)
                      throws WavesetException
Throws:
WavesetException

queryInt

public static int queryInt(java.sql.Connection c,
                           java.lang.String q,
                           java.lang.String arg)
                    throws WavesetException
Run a query and return the value of the first column in the first result row as an int.

Throws:
WavesetException

parameterizedQueryInt

public static int parameterizedQueryInt(java.sql.Connection c,
                                        java.lang.String q,
                                        java.util.List params)
                                 throws WavesetException
Run a query and return the value of the first column in the first result row as an int.

Throws:
WavesetException

queryDate

public static java.util.Date queryDate(java.sql.Connection c,
                                       java.lang.String q,
                                       java.lang.String arg)
                                throws java.sql.SQLException
Run a query and return the value of the first column in the first result row as a Date.

Throws:
java.sql.SQLException

parameterizedQueryDate

public static java.util.Date parameterizedQueryDate(java.sql.Connection c,
                                                    java.lang.String q,
                                                    java.util.List params)
                                             throws java.sql.SQLException
Run a query and return the value of the first column in the first result row as a Date.

Throws:
java.sql.SQLException

queryString

public static java.lang.String queryString(java.sql.Connection c,
                                           java.lang.String q,
                                           java.lang.String arg)
                                    throws java.sql.SQLException
Run a query and return the value of the first column in the first result row as a String.

Throws:
java.sql.SQLException

parameterizedQueryString

public static java.lang.String parameterizedQueryString(java.sql.Connection c,
                                                        java.lang.String q,
                                                        java.util.List params)
                                                 throws java.sql.SQLException
Run a query and return the value of the first column in the first result row as a String.

Throws:
java.sql.SQLException

queryClob

public static java.sql.Clob queryClob(java.sql.Connection c,
                                      java.lang.String q,
                                      java.lang.String arg)
                               throws java.sql.SQLException
Run a query and return the value of the first column in the first result row as a Clob.

Throws:
java.sql.SQLException

parameterizedQueryClob

public static java.sql.Clob parameterizedQueryClob(java.sql.Connection c,
                                                   java.lang.String q,
                                                   java.util.List params)
                                            throws java.sql.SQLException
Run a query and return the value of the first column in the first result row as a Clob.

Throws:
java.sql.SQLException

queryClobString

public static java.lang.String queryClobString(java.sql.Connection c,
                                               java.lang.String q,
                                               java.lang.String arg)
                                        throws java.sql.SQLException
Run a query and return the value of the first (Clob) column in the first result row as a String.

Throws:
java.sql.SQLException

parameterizedQueryClobString

public static java.lang.String parameterizedQueryClobString(java.sql.Connection c,
                                                            java.lang.String q,
                                                            java.util.List params)
                                                     throws java.sql.SQLException
Run a query and return the value of the first (Clob) column in the first result row as a String.

Throws:
java.sql.SQLException

queryList

public static java.util.List queryList(java.sql.Connection c,
                                       java.lang.String q,
                                       java.lang.String arg)
                                throws java.sql.SQLException
Run a query and return a List of the first columns in each row.

Throws:
java.sql.SQLException

parameterizedQueryList

public static java.util.List parameterizedQueryList(java.sql.Connection c,
                                                    java.lang.String q,
                                                    java.util.List params)
                                             throws java.sql.SQLException
Run a query and return a List of the first columns in each row.

Throws:
java.sql.SQLException

queryRecords

public static java.util.List queryRecords(java.sql.Connection c,
                                          java.lang.String q,
                                          java.lang.String arg)
                                   throws java.sql.SQLException
Run a query and return a List of Maps containing the data for each matching row. Each row's Map is keyed by column name.

Throws:
java.sql.SQLException

parameterizedQueryRecords

public static java.util.List parameterizedQueryRecords(java.sql.Connection c,
                                                       java.lang.String q,
                                                       java.util.List params)
                                                throws java.sql.SQLException
Run a query and return a List of Maps containing the data for each matching row. Each row's Map is keyed by column name.

Throws:
java.sql.SQLException

getDataSourceObject

public static javax.sql.DataSource getDataSourceObject(java.lang.String factoryClass,
                                                       java.lang.String path)
                                                throws ConfigurationError
Retrieves a JDBC 2.0 DataSource using JNDI.

Throws:
ConfigurationError

getDataSourceObject

public static javax.sql.DataSource getDataSourceObject(java.lang.String factoryClass,
                                                       java.lang.String path,
                                                       java.lang.String providerUrl)
                                                throws ConfigurationError
Retrieves a JDBC 2.0 DataSource using JNDI.

Throws:
ConfigurationError

getDataSourceObject

public static javax.sql.DataSource getDataSourceObject(java.lang.String factoryClass,
                                                       java.lang.String path,
                                                       java.util.Properties props)
                                                throws ConfigurationError
Retrieves a JDBC 2.0 DataSource using JNDI.

Throws:
ConfigurationError

formatUrl

public static java.lang.String formatUrl(java.lang.String template,
                                         java.lang.String host,
                                         java.lang.String port,
                                         java.lang.String database)
Given a URL template and arguments, format a template. Recognized template characters are: % literal % h host p port d database


getConnection

public static java.sql.Connection getConnection(java.util.Map args)
                                         throws WavesetException
Establish a connection. It is relatively uncommon for a rule to call this directly, though it might be used for more control

Throws:
WavesetException

closeConnection

public static void closeConnection(java.sql.Connection con)
Close a connection quietly.


queryInt

public static int queryInt(java.util.Map args)
                    throws WavesetException
Run a query and return the value of the first column in the first result row as an int.

Throws:
WavesetException

queryDate

public static java.util.Date queryDate(java.util.Map args)
                                throws WavesetException
Run a query and return the value of the first column in the first result row as a Date.

Throws:
WavesetException

queryString

public static java.lang.String queryString(java.util.Map args)
                                    throws WavesetException
Run a query and return the value of the first column in the first result row as a String.

Throws:
WavesetException

queryClob

public static java.sql.Clob queryClob(java.util.Map args)
                               throws WavesetException
Run a query and return the value of the first column in the first result row as a Clob.

Throws:
WavesetException

queryClobString

public static java.lang.String queryClobString(java.util.Map args)
                                        throws WavesetException
Run a query and return the value of the first (Clob) column in the first result row as a String.

Throws:
WavesetException

queryList

public static java.util.List queryList(java.util.Map args)
                                throws WavesetException
Run a query and return a List of the first columns in each row.

Throws:
WavesetException

queryRecords

public static java.util.List queryRecords(java.util.Map args)
                                   throws WavesetException
Run a query and return a List of Maps containing the data for each matching row. Each row's Map is keyed by column name.

Throws:
WavesetException

sql

public static void sql(java.util.Map args)
                throws WavesetException
Run specified SQL without obtaining a result.

Throws:
WavesetException

update

public static int update(java.util.Map args)
                  throws WavesetException
Run specified DML, returning number of affected rows.

Throws:
WavesetException

dumpArguments

public static void dumpArguments(java.lang.String method,
                                 java.util.Map map)

closeStatement

public static void closeStatement(java.sql.PreparedStatement stmt)
Close a statement quietly.


closeResult

public static void closeResult(java.sql.ResultSet res)
Close a result, quietly.