org.rhq.core.util.jdbc
Class JDBCUtil

java.lang.Object
  extended by org.rhq.core.util.jdbc.JDBCUtil

public class JDBCUtil
extends Object

Take care of some JDBC related stuff. Mostly closing resources

Author:
Heiko W. Rupp

Constructor Summary
JDBCUtil()
           
 
Method Summary
static void bindNTimes(PreparedStatement ps, int[] values, int startingBinding)
          Bind the passed values to the parameters of the PreparedStatement, starting at position startBinding
static String convertSQLExceptionToString(SQLException e)
           
static String generateInBinds(int count)
          Generate count '? separated by comma
static String getNextValSql(Connection conn, String tableName)
          Generate the correct SQL statement to obtain the next value from a sequence/table generator for the passed table.
static void safeClose(Connection con)
           
static void safeClose(Connection conn, Statement stm, ResultSet rs)
           
static void safeClose(InputStream in)
          Deprecated. This should correctly be handled at the place where the stream is about to be closed JBNADM-2600
static void safeClose(OutputStream out)
          Deprecated. This should correctly be handled at the place where the stream is about to be closed JBNADM-2600
static void safeClose(Reader reader)
          Deprecated. This should correctly be handled at the place where the stream is about to be closed JBNADM-2600
static void safeClose(ResultSet rs)
           
static void safeClose(Statement statement)
           
static void safeClose(Statement stm, ResultSet rs)
           
static void safeClose(Writer writer)
          Deprecated. This should correctly be handled at the place where the stream is about to be closed JBNADM-2600
static String transformQueryForMultipleInParameters(String query, String replaceable, int bindCount)
          Populate the passed query with bindCount number of placeholders '?'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCUtil

public JDBCUtil()
Method Detail

safeClose

public static void safeClose(Statement stm,
                             ResultSet rs)

safeClose

public static void safeClose(Connection conn,
                             Statement stm,
                             ResultSet rs)

safeClose

public static void safeClose(Connection con)

safeClose

public static void safeClose(ResultSet rs)

safeClose

public static void safeClose(Statement statement)

bindNTimes

public static void bindNTimes(PreparedStatement ps,
                              int[] values,
                              int startingBinding)
                       throws SQLException
Bind the passed values to the parameters of the PreparedStatement, starting at position startBinding

Parameters:
ps - PreparedStatement to use
values - the array of int values to fill in
startingBinding - the starting position of the parameter to fill in
Throws:
SQLException - if the Statement.setInt() call fails

transformQueryForMultipleInParameters

public static String transformQueryForMultipleInParameters(String query,
                                                           String replaceable,
                                                           int bindCount)
Populate the passed query with bindCount number of placeholders '?'. The method will not put necessary parenteses around the placeholders.

Parameters:
query - the original query including text to replace
replaceable - the part of the original query that should be replaced by '?'s.
bindCount - how many placeholders '?' should be generated
Returns:
The modified query

generateInBinds

public static String generateInBinds(int count)
Generate count '? separated by comma


getNextValSql

public static String getNextValSql(Connection conn,
                                   String tableName)
Generate the correct SQL statement to obtain the next value from a sequence/table generator for the passed table. The passed connection gets closed in case of an error.

Parameters:
conn - A valid database connection
tableName - The name of the table to use
Returns:
A statement that obtains the next value for the passed table

safeClose

@Deprecated
public static void safeClose(InputStream in)
Deprecated. This should correctly be handled at the place where the stream is about to be closed JBNADM-2600


safeClose

@Deprecated
public static void safeClose(OutputStream out)
Deprecated. This should correctly be handled at the place where the stream is about to be closed JBNADM-2600


safeClose

@Deprecated
public static void safeClose(Reader reader)
Deprecated. This should correctly be handled at the place where the stream is about to be closed JBNADM-2600


safeClose

@Deprecated
public static void safeClose(Writer writer)
Deprecated. This should correctly be handled at the place where the stream is about to be closed JBNADM-2600


convertSQLExceptionToString

public static String convertSQLExceptionToString(SQLException e)


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.