public static Object fetchFromDBSql(final Connection connection,final String sqlQuery) throws SQLException {
  PreparedStatement statement=null;
  ResultSet resultSet=null;
  try {
    statement=connection.prepareStatement(sqlQuery);
    resultSet=statement.executeQuery();
    if (resultSet != null && resultSet.next())     return resultSet.getString(1);
 else     return null;
  }
 catch (  final SQLException e) {
    final String errMsg="Exception while executing query [" + sqlQuery + "]";
    LOGGER.error(errMsg,e);
    throw new ApplicationRuntimeException(errMsg,e);
  }
 finally {
    if (statement != null)     statement.close();
    if (resultSet != null)     resultSet.close();
  }
}

public static Object fetchFromDBSql ( final Connection connection , final String sqlQuery ) throws SQLException { PreparedStatement statement = null ; ResultSet resultSet = null ; try { statement = connection . prepareStatement ( sqlQuery ) ; resultSet = statement . executeQuery ( ) ; if ( resultSet != null && resultSet . next ( ) ) return resultSet . getString ( 1 ) ; else return null ; } catch ( final SQLException e ) { final String errMsg = "Exception while executing query [" + sqlQuery + "]" ; LOGGER . error ( errMsg , e ) ; throw new ApplicationRuntimeException ( errMsg , e ) ; } finally { if ( statement != null ) statement . close ( ) ; if ( resultSet != null ) resultSet . close ( ) ; } }
executes given sql query ( which is expected to return a single object ) and returns the output . returns null if query doesn ' t fetch any data .
