net.hasor.jdbc.core.util
类 JdbcUtils

java.lang.Object
  继承者 net.hasor.jdbc.core.util.JdbcUtils

public class JdbcUtils
extends Object

版本:
: 2013-10-12
作者:
赵永春(zyc@hasor.net)

字段摘要
static int TYPE_UNKNOWN
           
 
构造方法摘要
JdbcUtils()
           
 
方法摘要
static void closeConnection(Connection con)
          Close the given JDBC Connection and ignore any thrown exception.
static void closeResultSet(ResultSet rs)
          Close the given JDBC ResultSet and ignore any thrown exception.
static void closeStatement(Statement stmt)
          Close the given JDBC Statement and ignore any thrown exception.
static Object getResultSetValue(ResultSet rs, int index)
          Retrieve a JDBC column value from a ResultSet, using the most appropriate value type.
static Object getResultSetValue(ResultSet rs, int index, Class requiredType)
          Retrieve a JDBC column value from a ResultSet, using the specified value type.
static String lookupColumnName(ResultSetMetaData resultSetMetaData, int columnIndex)
          Determine the column name to use.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

TYPE_UNKNOWN

public static final int TYPE_UNKNOWN
另请参见:
常量字段值
构造方法详细信息

JdbcUtils

public JdbcUtils()
方法详细信息

lookupColumnName

public static String lookupColumnName(ResultSetMetaData resultSetMetaData,
                                      int columnIndex)
                               throws SQLException
Determine the column name to use. The column name is determined based on a lookup using ResultSetMetaData.

This method implementation takes into account recent clarifications expressed in the JDBC 4.0 specification:

columnLabel - the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column.

参数:
resultSetMetaData - the current meta data to use
columnIndex - the index of the column for the look up
返回:
the column name to use
抛出:
SQLException - in case of lookup failure

getResultSetValue

public static Object getResultSetValue(ResultSet rs,
                                       int index,
                                       Class requiredType)
                                throws SQLException
Retrieve a JDBC column value from a ResultSet, using the specified value type.

Uses the specifically typed ResultSet accessor methods, falling back to getResultSetValue(java.sql.ResultSet, int) for unknown types.

Note that the returned value may not be assignable to the specified required type, in case of an unknown type. Calling code needs to deal with this case appropriately, e.g. throwing a corresponding exception.

参数:
rs - is the ResultSet holding the data
index - is the column index
requiredType - the required value type (may be null)
返回:
the value object
抛出:
SQLException - if thrown by the JDBC API

getResultSetValue

public static Object getResultSetValue(ResultSet rs,
                                       int index)
                                throws SQLException
Retrieve a JDBC column value from a ResultSet, using the most appropriate value type. The returned value should be a detached value object, not having any ties to the active ResultSet: in particular, it should not be a Blob or Clob object but rather a byte array respectively String representation.

Uses the getObject(index) method, but includes additional "hacks" to get around Oracle 10g returning a non-standard object for its TIMESTAMP datatype and a java.sql.Date for DATE columns leaving out the time portion: These columns will explicitly be extracted as standard java.sql.Timestamp object.

参数:
rs - is the ResultSet holding the data
index - is the column index
返回:
the value object
抛出:
SQLException - if thrown by the JDBC API
另请参见:
Blob, Clob, Timestamp

closeConnection

public static void closeConnection(Connection con)
Close the given JDBC Connection and ignore any thrown exception. This is useful for typical finally blocks in manual JDBC code.

参数:
con - the JDBC Connection to close (may be null)

closeStatement

public static void closeStatement(Statement stmt)
Close the given JDBC Statement and ignore any thrown exception. This is useful for typical finally blocks in manual JDBC code.

参数:
stmt - the JDBC Statement to close (may be null)

closeResultSet

public static void closeResultSet(ResultSet rs)
Close the given JDBC ResultSet and ignore any thrown exception. This is useful for typical finally blocks in manual JDBC code.

参数:
rs - the JDBC ResultSet to close (may be null)


Copyright © 2013-2014. All Rights Reserved.