org.compass.gps.device.jdbc
Class JdbcUtils

java.lang.Object
  extended by org.compass.gps.device.jdbc.JdbcUtils

public abstract class JdbcUtils
extends Object

A set of Jdbc utilities.

Author:
kimchy

Constructor Summary
JdbcUtils()
           
 
Method Summary
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 int getColumnIndexFromColumnName(ResultSetMetaData metaData, String columnName)
          Returns the column index for the guven column name.
static Connection getConnection(DataSource dataSource)
          Returns a jdbc connection, and in case of failure, wraps the sql exception with a Jdbc device exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcUtils

public JdbcUtils()
Method Detail

getConnection

public static Connection getConnection(DataSource dataSource)
                                throws JdbcGpsDeviceException
Returns a jdbc connection, and in case of failure, wraps the sql exception with a Jdbc device exception.

Parameters:
dataSource -
Returns:
A connection from the datasource.
Throws:
JdbcGpsDeviceException

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.

Parameters:
con - The JDBC Connection to close

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.

Parameters:
stmt - The JDBC Statement to close

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.

Parameters:
rs - the JDBC ResultSet to close

getColumnIndexFromColumnName

public static int getColumnIndexFromColumnName(ResultSetMetaData metaData,
                                               String columnName)
                                        throws SQLException
Returns the column index for the guven column name. Note that if there are two columns with the same name, the first onde index will be returned.

-1 is returned if none is found.

Throws:
SQLException


Copyright (c) 2004-2009 The Compass Project.