DBUtil (Hyperic HQ Plugin API)
Keywords: org.hyperic.util.jdbc.DBUtil class

Overview | Package | Class | Tree | Deprecated | Index | Help
| Hyperic HQ Plugin API v. 4.4.0.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.hyperic.util.jdbc
Class DBUtil

    java.lang.Object
      org.hyperic.util.jdbc.DBUtil

    public class DBUtil

extends java.lang.Object

Field Summary
`static int` | `DATABASE_MYSQL5`
`static int` | `DATABASE_ORACLE_10`
`static int` | `DATABASE_ORACLE_11`
`static int` | `DATABASE_ORACLE_8`
`static int` | `DATABASE_ORACLE_9`
`static int` | `DATABASE_POSTGRESQL_7`
`static int` | `DATABASE_POSTGRESQL_8`
`static int` | `DATABASE_UNKNOWN`
`static int` | `IN_CHUNK_SIZE`
`protected static org.apache.commons.logging.Log` | `log`
`static int` | `MYSQL_LOCAL_CONN_ERROR`
`static int` | `MYSQL_REMOTE_CONN_ERROR`
`static int` | `ORACLE_ERROR_DIVIDE_BY_ZERO`
`static int` | `ORACLE_ERROR_NOT_AVAILABLE`
`static int` | `POSTGRES_CONNECTION_EXCEPTION`
`static int` | `POSTGRES_CONNECTION_FAILURE`
`static int` | `POSTGRES_ERROR_DIVIDE_BY_ZERO`
`static int` | `POSTGRES_UNABLE_TO_CONNECT`

Method Summary
`static boolean` | `checkColumnExists(java.lang.String ctx, java.sql.Connection c, java.lang.String table, java.lang.String column)` Check to see if a column exists in a table.
`static boolean` | `checkTableExists(java.sql.Connection conn, java.lang.String table)`
`static boolean` | `checkTableExists(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String table)`
`static void` | `closeConnection(java.lang.Object ctx, java.sql.Connection c)` Close a database connection.
`static void` | `closeJDBCObjects(java.lang.Object ctx, java.sql.Connection c, java.sql.Statement s, java.sql.ResultSet rs)` Close a connection, statement, and result set in one fell swoop.
`static void` | `closeResultSet(java.lang.Object ctx, java.sql.ResultSet rs)` Close a database result set.
`static void` | `closeStatement(java.lang.Object ctx, java.sql.Statement s)` Close a database statement.
`static java.lang.String` | `composeConjunctions(java.lang.String column, int iterations)` Creates the SQL query that is used in PreparedStatement for 0 or more values for a given column.
`static byte[]` | `getBlobColumn(java.sql.ResultSet rs, int columnIndex)` Get a database specific blob column, when you already have the result set open
`static java.lang.String` | `getBooleanType(java.sql.Connection conn)` Get the type for a boolean as a string for the required database.
`static java.lang.String` | `getBooleanValue(boolean bool, java.sql.Connection conn)` Get the value for a boolean as a string for the required database
`static java.sql.Connection` | `getConnByContext(javax.naming.Context jndiCtx, java.lang.String dsName)` get a connection for a datasource registered in JNDI
`static int` | `getDBType(java.sql.Connection conn)` Given a Connection object, this method returns a constant indicating what type of database the Connection is connected to.
`static int` | `getNextSequenceValue(java.lang.String ctx, java.sql.Connection conn, java.lang.String table, java.lang.String key)` Get the next value of a sequence
`static boolean` | `isMySQL(java.sql.Connection c)` Is the database MySQL?
`static boolean` | `isMySQL(int type)`
`static boolean` | `isOracle(java.sql.Connection c)` Is the database Oracle?
`static boolean` | `isOracle(int type)`
`static boolean` | `isPostgreSQL(java.sql.Connection c)` Is the database PostgreSQL?
`static boolean` | `isPostgreSQL(int type)`
`static void` | `replacePlaceHolder(java.lang.StringBuffer buf, java.lang.String repl)`
`static void` | `replacePlaceHolders(java.lang.StringBuffer buf, java.lang.Object[] objs)`
`static int` | `seek(java.sql.ResultSet rs, PageControl pc)` Seek through the specified ResultSet to the beginning of the page specified by the PageControl
`static void` | `setBooleanValue(boolean bool, java.sql.Connection conn, java.sql.PreparedStatement ps, int idx)` Fill out a PreparedStatement correctly with a boolean.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### log

    protected static final org.apache.commons.logging.Log log

### ORACLE_ERROR_DIVIDE_BY_ZERO

    public static final int ORACLE_ERROR_DIVIDE_BY_ZERO

See Also:
  Constant Field Values

### ORACLE_ERROR_NOT_AVAILABLE

    public static final int ORACLE_ERROR_NOT_AVAILABLE

See Also:
  Constant Field Values

### POSTGRES_ERROR_DIVIDE_BY_ZERO

    public static final int POSTGRES_ERROR_DIVIDE_BY_ZERO

See Also:
  Constant Field Values

### POSTGRES_CONNECTION_EXCEPTION

    public static final int POSTGRES_CONNECTION_EXCEPTION

See Also:
  Constant Field Values

### POSTGRES_CONNECTION_FAILURE

    public static final int POSTGRES_CONNECTION_FAILURE

See Also:
  Constant Field Values

### POSTGRES_UNABLE_TO_CONNECT

    public static final int POSTGRES_UNABLE_TO_CONNECT

See Also:
  Constant Field Values

### MYSQL_LOCAL_CONN_ERROR

    public static final int MYSQL_LOCAL_CONN_ERROR

See Also:
  Constant Field Values

### MYSQL_REMOTE_CONN_ERROR

    public static final int MYSQL_REMOTE_CONN_ERROR

See Also:
  Constant Field Values

### DATABASE_UNKNOWN

    public static final int DATABASE_UNKNOWN

See Also:
  Constant Field Values

### DATABASE_POSTGRESQL_7

    public static final int DATABASE_POSTGRESQL_7

See Also:
  Constant Field Values

### DATABASE_POSTGRESQL_8

    public static final int DATABASE_POSTGRESQL_8

See Also:
  Constant Field Values

### DATABASE_ORACLE_8

    public static final int DATABASE_ORACLE_8

See Also:
  Constant Field Values

### DATABASE_ORACLE_9

    public static final int DATABASE_ORACLE_9

See Also:
  Constant Field Values

### DATABASE_ORACLE_10

    public static final int DATABASE_ORACLE_10

See Also:
  Constant Field Values

### DATABASE_ORACLE_11

    public static final int DATABASE_ORACLE_11

See Also:
  Constant Field Values

### DATABASE_MYSQL5

    public static final int DATABASE_MYSQL5

See Also:
  Constant Field Values

### IN_CHUNK_SIZE

    public static final int IN_CHUNK_SIZE

See Also:
  Constant Field Values

Method Detail

### closeConnection

    public static void closeConnection(java.lang.Object ctx,
                                       java.sql.Connection c)

  Close a database connection. No exception is thrown if it fails, but a warning is logged.

  Parameters:
    `ctx` - The logging context to use if a warning should be issued.
    `c` - The connection to close.

### closeStatement

    public static void closeStatement(java.lang.Object ctx,
                                      java.sql.Statement s)

  Close a database statement. No exception is thrown if it fails, but a warning is logged.

  Parameters:
    `ctx` - The logging context to use if a warning should be issued.
    `s` - The statement to close.

### closeResultSet

    public static void closeResultSet(java.lang.Object ctx,
                                      java.sql.ResultSet rs)

  Close a database result set. No exception is thrown if it fails, but a warning is logged.

  Parameters:
    `ctx` - The logging context to use if a warning should be issued.
    `rs` - The result set to close.

### closeJDBCObjects

    public static void closeJDBCObjects(java.lang.Object ctx,
                                        java.sql.Connection c,
                                        java.sql.Statement s,
                                        java.sql.ResultSet rs)

  Close a connection, statement, and result set in one fell swoop. You can pass null for any argument and all will be OK :) No exception is thrown if any close fails, but warnings will be logged.

  Parameters:
    `ctx` - The logging context to use if warnings should be issued.
    `c` - The connection to close.
    `s` - The statement set to close.
    `rs` - The result set to close.

### getNextSequenceValue

    public static int getNextSequenceValue(java.lang.String ctx,
                                           java.sql.Connection conn,
                                           java.lang.String table,
                                           java.lang.String key)
                                    throws java.sql.SQLException

  Get the next value of a sequence

  Throws:
    `java.sql.SQLException`

### getDBType

    public static int getDBType(java.sql.Connection conn)
                         throws java.sql.SQLException

  Given a Connection object, this method returns a constant indicating what type of database the Connection is connected to.

  Parameters:
    `conn` - The connection whose database type the caller wished to ascertain.
  Returns:
    One of the DATABASE_XXX constants defined in this class.
  Throws:
    `java.sql.SQLException`

### isPostgreSQL

    public static boolean isPostgreSQL(java.sql.Connection c)
                                throws java.sql.SQLException

  Is the database PostgreSQL?

  Throws:
    `java.sql.SQLException`

### isPostgreSQL

    public static boolean isPostgreSQL(int type)

### isOracle

    public static boolean isOracle(java.sql.Connection c)
                            throws java.sql.SQLException

  Is the database Oracle?

  Throws:
    `java.sql.SQLException`

### isOracle

    public static boolean isOracle(int type)

### isMySQL

    public static boolean isMySQL(java.sql.Connection c)
                           throws java.sql.SQLException

  Is the database MySQL?

  Throws:
    `java.sql.SQLException`

### isMySQL

    public static boolean isMySQL(int type)

### getConnByContext

    public static java.sql.Connection getConnByContext(javax.naming.Context jndiCtx,
                                                       java.lang.String dsName)
                                                throws java.sql.SQLException,
                                                       javax.naming.NamingException

  get a connection for a datasource registered in JNDI

  Throws:
    `java.sql.SQLException`
    `javax.naming.NamingException`

### getBlobColumn

    public static byte[] getBlobColumn(java.sql.ResultSet rs,
                                       int columnIndex)
                                throws java.sql.SQLException

  Get a database specific blob column, when you already have the result set open

  Parameters:
    `columnIndex` - where to read the blob column form.
  Throws:
    `java.sql.SQLException`

### getBooleanType

    public static java.lang.String getBooleanType(java.sql.Connection conn)
                                           throws java.sql.SQLException

  Get the type for a boolean as a string for the required database. This should use the same XML file as DBSetup uses, but this will work for now.

  Parameters:
    `conn` - - a connection
  Returns:
    booleanStr - the appropriate boolean type for the db you're using
  Throws:
    `java.sql.SQLException`

### getBooleanValue

    public static java.lang.String getBooleanValue(boolean bool,
                                                   java.sql.Connection conn)
                                            throws java.sql.SQLException

  Get the value for a boolean as a string for the required database

  Parameters:
    `bool` - - the boolean you want
    `conn` - - a connection
  Returns:
    booleanStr - the appropriate boolean string for the db you're using
  Throws:
    `java.sql.SQLException`

### setBooleanValue

    public static void setBooleanValue(boolean bool,
                                       java.sql.Connection conn,
                                       java.sql.PreparedStatement ps,
                                       int idx)
                                throws java.sql.SQLException

  Fill out a PreparedStatement correctly with a boolean.

  Parameters:
    `bool` - - the boolean you want
    `conn` - - a connection
  Throws:
    `java.sql.SQLException`

### seek

    public static int seek(java.sql.ResultSet rs,
                           PageControl pc)
                    throws java.sql.SQLException

  Seek through the specified ResultSet to the beginning of the page specified by the PageControl

  Parameters:
    `rs` - The result set to seek through.
    `pc` - The page control that indicates how far to seek
  Returns:
    The number of records actually skipped over in the seek.
  Throws:
    `java.sql.SQLException`

### checkColumnExists

    public static boolean checkColumnExists(java.lang.String ctx,
                                            java.sql.Connection c,
                                            java.lang.String table,
                                            java.lang.String column)
                                     throws java.sql.SQLException

  Check to see if a column exists in a table.

  Parameters:
    `ctx` - The logging context to use.
    `c` - The DB connection to use.
    `table` - The table to check.
    `column` - The column to look for. This is done in a case-insensitive manner.
  Returns:
    true if the column exists in the table, false otherwise
  Throws:
    `java.sql.SQLException` - If any kind of DB error occurs.

### checkTableExists

    public static boolean checkTableExists(java.lang.String url,
                                           java.lang.String user,
                                           java.lang.String password,
                                           java.lang.String table)
                                    throws DriverLoadException,
                                           java.sql.SQLException

  Throws:
    `DriverLoadException`
    `java.sql.SQLException`

### checkTableExists

    public static boolean checkTableExists(java.sql.Connection conn,
                                           java.lang.String table)
                                    throws java.sql.SQLException

  Throws:
    `java.sql.SQLException`

### composeConjunctions

    public static java.lang.String composeConjunctions(java.lang.String column,
                                                       int iterations)

  Creates the SQL query that is used in PreparedStatement for 0 or more values for a given column. For example:

  SELECT id FROM TABLE WHERE id IN (?, ?, ?) SELECT id FROM TABLE WHERE id = ?

  Parameters:
    `column` - the name of the column to query against
    `iterations` - the number of variables
  Returns:
    the WHERE clause (without the WHERE keyword)

### replacePlaceHolder

    public static void replacePlaceHolder(java.lang.StringBuffer buf,
                                          java.lang.String repl)

### replacePlaceHolders

    public static void replacePlaceHolders(java.lang.StringBuffer buf,
                                           java.lang.Object[] objs)

Overview | Package | Class | Tree | Deprecated | Index | Help
| Hyperic HQ Plugin API v. 4.4.0.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.