Created
March 8, 2017 12:55
-
-
Save wpride/7741538b940f64ede78cdffd5f9d3a7f to your computer and use it in GitHub Desktop.
Look up a value in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String retrieveCacheValue(String entityKey, String cacheKey) { | |
Connection connection = null; | |
PreparedStatement preparedStatement = null; | |
try { | |
connection = dataSource.getConnection(); | |
preparedStatement = SqlHelper.prepareTableSelectStatement(connection, | |
TABLE_NAME, | |
new String[]{COL_CACHE_NAME, COL_ENTITY_KEY, COL_CACHE_KEY}, | |
new String[]{mCacheName, entityKey, cacheKey}); | |
ResultSet resultSet = preparedStatement.executeQuery(); | |
if (resultSet.next()) { | |
return resultSet.getString(resultSet.findColumn(COL_VALUE)); | |
} else { | |
return null; | |
} | |
} catch (SQLException e) { | |
throw new RuntimeException(e); | |
} finally { | |
if (connection != null) { | |
try { | |
connection.close(); | |
} catch (SQLException e) { | |
log.debug("Exception closing connection ", e); | |
} | |
} | |
if (preparedStatement != null) { | |
try { | |
preparedStatement.close(); | |
} catch (SQLException e) { | |
log.debug("Exception closing prepared statement ", e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment