List of usage examples for java.sql ResultSet getTimestamp
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Timestamp
object in the Java programming language. From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java
/** * @see eionet.meta.dao.ISchemaSetDAO#getWorkingCopyOfSchemaSet(int) *//*from w ww. j a va 2 s . c o m*/ @Override public SchemaSet getWorkingCopyOfSchemaSet(int checkedOutCopyId) { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("checkedOutCopyId", checkedOutCopyId); SchemaSet result = getNamedParameterJdbcTemplate().queryForObject(GET_WORKING_COPY_OF_SQL, parameters, new RowMapper<SchemaSet>() { @Override public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException { SchemaSet ss = new SchemaSet(); ss.setId(rs.getInt("SCHEMA_SET_ID")); ss.setIdentifier(rs.getString("IDENTIFIER")); ss.setContinuityId(rs.getString("CONTINUITY_ID")); ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS"))); ss.setWorkingCopy(rs.getBoolean("WORKING_COPY")); ss.setWorkingUser(rs.getString("WORKING_USER")); ss.setDateModified(rs.getTimestamp("DATE_MODIFIED")); ss.setUserModified(rs.getString("USER_MODIFIED")); ss.setComment(rs.getString("COMMENT")); ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID")); ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED")); return ss; } }); return result; }
From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java
/** * @see eionet.meta.dao.ISchemaSetDAO#getWorkingCopiesOf(java.lang.String) *///from ww w . ja v a 2 s . com @Override public List<SchemaSet> getWorkingCopiesOf(String userName) { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("userName", userName); List<SchemaSet> resultList = getNamedParameterJdbcTemplate().query(GET_WORKING_COPIES_SQL, parameters, new RowMapper<SchemaSet>() { @Override public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException { SchemaSet ss = new SchemaSet(); ss.setId(rs.getInt("SCHEMA_SET_ID")); ss.setIdentifier(rs.getString("IDENTIFIER")); ss.setContinuityId(rs.getString("CONTINUITY_ID")); ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS"))); ss.setWorkingCopy(rs.getBoolean("WORKING_COPY")); ss.setWorkingUser(rs.getString("WORKING_USER")); ss.setDateModified(rs.getTimestamp("DATE_MODIFIED")); ss.setUserModified(rs.getString("USER_MODIFIED")); ss.setComment(rs.getString("COMMENT")); ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID")); ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED")); return ss; } }); return resultList; }
From source file:edu.ku.brc.specify.conversion.ConvertMiscData.java
/** * @param oldDBConn/* ww w. ja v a 2s.c om*/ * @param newDBConn * @param disciplineID * @return */ public static boolean convertKUFishObsData(final Connection oldDBConn, final Connection newDBConn) { IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); IdMapperIFace coMapper = IdMapperMgr.getInstance().addTableMapper("collectionobjectcatalog", "CollectionObjectCatalogID", false); PreparedStatement pStmt1 = null; PreparedStatement pStmt2 = null; PreparedStatement pStmt3 = null; try { pStmt1 = newDBConn.prepareStatement( "INSERT INTO collectionobjectattribute (Remarks, CollectionMemberID, TimestampCreated, TimestampModified, Version) VALUES(?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); pStmt2 = newDBConn.prepareStatement( "UPDATE collectionobjectattribute SET Remarks=? WHERE CollectionObjectAttributeID = ?"); pStmt3 = newDBConn.prepareStatement( "UPDATE collectionobject SET CollectionObjectAttributeID=? WHERE CollectionObjectID = ?"); String sql = " SELECT BiologicalObjectID, Text1, TimestampCreated, TimestampModified FROM observation WHERE Text1 IS NOT NULL AND LENGTH(Text1) > 0"; Statement stmt = oldDBConn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { int oldCOId = rs.getInt(1); Integer newCOId = coMapper.get(oldCOId); if (newCOId != null) { sql = "SELECT CollectionObjectAttributeID, CollectionMemberID FROM collectionobject WHERE CollectionObjectID = " + newCOId; Object[] row = BasicSQLUtils.getRow(sql); if (row == null || row.length == 0) { log.error("Couldn't get record for newCOId " + newCOId); continue; } Integer newCOAId = (Integer) row[0]; Integer collMemId = (Integer) row[1]; if (newCOAId != null) // Do Update { pStmt2.setString(1, rs.getString(2)); pStmt2.setInt(2, newCOAId); pStmt2.executeUpdate(); } else // Do Insert { pStmt1.setString(1, rs.getString(2)); pStmt1.setInt(2, collMemId); pStmt1.setTimestamp(3, rs.getTimestamp(3)); pStmt1.setTimestamp(4, rs.getTimestamp(4)); pStmt1.setInt(5, 1); pStmt1.executeUpdate(); newCOAId = BasicSQLUtils.getInsertedId(pStmt1); } pStmt3.setInt(1, newCOAId); pStmt3.setInt(2, newCOId); pStmt3.executeUpdate(); } else { log.error("No mapped CO for Obs.BiologicalObjectID " + oldCOId); } } rs.close(); stmt.close(); return true; } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (pStmt1 != null) pStmt1.close(); if (pStmt2 != null) pStmt2.close(); if (pStmt3 != null) pStmt3.close(); } catch (Exception ex) { } } return false; }
From source file:com.sfs.dao.ObjectTypeDAOImpl.java
/** * Load object.// ww w .ja v a 2s . c o m * * @param rs the rs * * @return the object type bean * * @throws SQLException the SQL exception */ private ObjectTypeBean loadObject(final ResultSet rs) throws SQLException { ObjectTypeBean objectType = new ObjectTypeBean(); // Create item bean and fill with dataset info. objectType.setObjectTypeId(rs.getInt("ObjectTypeId")); objectType.setObject(rs.getString("Object")); objectType.setName(rs.getString("Name")); objectType.setClassName(rs.getString("Class")); objectType.setAbbreviation(rs.getString("Abbreviation")); objectType.setValue(rs.getDouble("Value")); objectType.setSecurity(rs.getString("Security")); objectType.setLdapMapping(1, rs.getString("LdapMapping")); objectType.setLdapMapping(2, rs.getString("SecondLdapMapping")); objectType.setLdapMapping(3, rs.getString("ThirdLdapMapping")); try { objectType.setCreated(rs.getTimestamp("Created")); } catch (SQLException sqe) { dataLogger.info("Could not load Created date: " + sqe.getMessage()); } objectType.setCreatedBy(rs.getString("CreatedBy")); try { objectType.setModified(rs.getTimestamp("Modified")); } catch (SQLException sqe) { dataLogger.info("Could not load Modified date: " + sqe.getMessage()); } objectType.setModifiedBy(rs.getString("ModifiedBy")); if (objectType.getCreatedBy() != null && this.userDAO != null) { try { objectType.setCreatedByUser(this.userDAO.loadCached(objectType.getCreatedBy())); } catch (Exception e) { dataLogger.info("Could not load CreatedBy UserBean for " + "ObjectTypeId = " + objectType.getObjectTypeId()); } } if (objectType.getModifiedBy() != null && this.userDAO != null) { try { objectType.setModifiedByUser(this.userDAO.loadCached(objectType.getModifiedBy())); } catch (Exception e) { dataLogger.info("Could not load ModifiedBy UserBean for " + "ObjectTypeId = " + objectType.getObjectTypeId()); } } return objectType; }
From source file:com.jjtree.servelet.Articles.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/* w ww . java2 s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); // one single article String pathInfo = request.getPathInfo(); int singleArticleID = -1; if (pathInfo != null) { String[] path = pathInfo.split("/"); singleArticleID = Integer.parseInt(path[1]); } // mutiple articles String category = request.getParameter("category"); int pageSize = 0; int pageIndex = 0; if (category != null) { pageSize = Integer.parseInt(request.getParameter("pageSize")); pageIndex = Integer.parseInt(request.getParameter("pageIndex")); } // search articles String query = request.getParameter("q"); if (query != null) { pageSize = Integer.parseInt(request.getParameter("pageSize")); pageIndex = Integer.parseInt(request.getParameter("pageIndex")); } try { // Register JDBC driver Class.forName(JConstant.JDBC_DRIVER); // Open a connection conn = DriverManager.getConnection(JConstant.DB_URL, JConstant.USER, JConstant.PASSWORD); // Execute SQL query stmt = conn.createStatement(); String sql = null; if (singleArticleID >= 0) { sql = "SELECT * FROM JArticle WHERE articleID = " + singleArticleID; } if (category != null) { if (category.equalsIgnoreCase(TOP)) { sql = "SELECT * FROM JArticle ORDER BY usefulValue DESC OFFSET " + pageSize * pageIndex + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY"; } if (category.equalsIgnoreCase(RECENT)) { sql = "SELECT * FROM JArticle ORDER BY createdAt DESC OFFSET " + pageSize * pageIndex + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY"; } // collection if (category.equalsIgnoreCase(COLLECTION) || category.equalsIgnoreCase(EDIT) || category.equalsIgnoreCase(REWARD) || category.equalsIgnoreCase(USEFUL) || category.equalsIgnoreCase(USELESS) || category.equalsIgnoreCase(SHARE)) { sql = getSqlQuery(category, request, pageSize, pageIndex); } } if (query != null) { sql = "SELECT * FROM JArticle WHERE title IN ( SELECT title FROM JArticle WHERE UPPER(title) LIKE UPPER('%" + query + "%') ORDER BY createdAt DESC ) OFFSET " + (pageIndex * pageSize) + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY"; } ResultSet rs = stmt.executeQuery(sql); JSONObject articlesObject = new JSONObject(); JSONArray articles = new JSONArray(); JSONArray paragraphs = new JSONArray(); // Extract data from result set while (rs.next()) { //Retrieve by column name int articleID = rs.getInt("articleID"); int authorID = rs.getInt("userID"); boolean isPrivate = rs.getBoolean("isPrivate"); String title = rs.getString("title"); Timestamp createdAt = rs.getTimestamp("createdAt"); Timestamp updatedAt = rs.getTimestamp("updatedAt"); int usefulValue = rs.getInt("usefulValue"); int uselessValue = rs.getInt("uselessValue"); int viewCount = rs.getInt("viewCount"); String accountUrl = "/accounts/" + authorID; JSONObject author = JServeletManager.fetchFrom(request, accountUrl); JSONObject article = new JSONObject(); Statement subStatement = conn.createStatement(); String subSql = "SELECT * FROM JParagraph WHERE articleID = " + articleID; ResultSet subRs = subStatement.executeQuery(subSql); while (subRs.next()) { int paragraphID = subRs.getInt("paragraphID"); int position = subRs.getInt("position"); String type = subRs.getString("type"); String content = subRs.getString("content"); JSONObject paragraph = new JSONObject(); paragraph.put("paragraphID", paragraphID); paragraph.put("position", position); paragraph.put("type", type); paragraph.put("content", content); paragraphs.put(paragraph); } article.put("articleID", articleID); article.put("authorID", authorID); article.put("isPrivate", isPrivate); article.put("title", title); article.put("createdAt", createdAt); article.put("updatedAt", updatedAt); article.put("usefulValue", usefulValue); article.put("uselessValue", uselessValue); article.put("viewCount", viewCount); article.put("paragraphs", paragraphs); article.put("author", author); PrintWriter writer = response.getWriter(); // single article if (singleArticleID >= 0) { writer.print(article); writer.flush(); } if (category != null || query != null) { articles.put(article); } } if (category != null || query != null) { articlesObject.put("articles", articles); PrintWriter writer = response.getWriter(); writer.print(articlesObject); writer.flush(); } // Clean-up environment rs.close(); stmt.close(); conn.close(); } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { //finally block used to close resources try { if (stmt != null) { stmt.close(); } } catch (SQLException se2) { } // nothing we can do try { if (conn != null) { conn.close(); } } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try }
From source file:CSVWriter.java
private static String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; // w ww . j a va2 s . co m switch (colType) { case Types.BIT: Object bit = rs.getObject(colIndex); if (bit != null) { value = String.valueOf(bit); } break; case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); if (!rs.wasNull()) { value = Boolean.valueOf(b).toString(); } break; case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: BigDecimal bd = rs.getBigDecimal(colIndex); if (bd != null) { value = "" + bd.doubleValue(); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: int intValue = rs.getInt(colIndex); if (!rs.wasNull()) { value = "" + intValue; } break; case Types.JAVA_OBJECT: Object obj = rs.getObject(colIndex); if (obj != null) { value = String.valueOf(obj); } break; case Types.DATE: java.sql.Date date = rs.getDate(colIndex); if (date != null) { value = DATE_FORMATTER.format(date);; } break; case Types.TIME: Time t = rs.getTime(colIndex); if (t != null) { value = t.toString(); } break; case Types.TIMESTAMP: Timestamp tstamp = rs.getTimestamp(colIndex); if (tstamp != null) { value = TIMESTAMP_FORMATTER.format(tstamp); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:com.sfs.whichdoctor.dao.EmailDAOImpl.java
/** * Load the EmailBean from the database. * * @param rs the rs/*from w w w . j a v a 2 s .c o m*/ * @return the email bean * @throws SQLException the sQL exception */ private EmailBean loadEmail(final ResultSet rs) throws SQLException { EmailBean emailAddress = new EmailBean(); emailAddress.setId(rs.getInt("EmailId")); emailAddress.setGUID(rs.getInt("GUID")); emailAddress.setReferenceGUID(rs.getInt("ReferenceGUID")); emailAddress.setContactClass(rs.getString("ContactClass")); emailAddress.setContactType(rs.getString("ContactType")); emailAddress.setDescription(rs.getString("Description")); emailAddress.setEmail(rs.getString("Email")); emailAddress.setEmailQuestions(rs.getBoolean("EmailQuestions")); emailAddress.setReturnedMail(rs.getBoolean("ReturnedMail")); emailAddress.setRequestNoMail(rs.getBoolean("RequestNoMail")); emailAddress.setPrimary(rs.getBoolean("PrimaryEmail")); emailAddress.setActive(rs.getBoolean("Active")); try { emailAddress.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error loading CreatedDate: " + sqe.getMessage()); } emailAddress.setCreatedBy(rs.getString("CreatedBy")); try { emailAddress.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error loading ModifiedDate: " + sqe.getMessage()); } emailAddress.setModifiedBy(rs.getString("ModifiedBy")); try { emailAddress.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error loading ExportedDate: " + sqe.getMessage()); } emailAddress.setExportedBy(rs.getString("ExportedBy")); return emailAddress; }
From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java
/** * @see eionet.meta.dao.ISchemaSetDAO#getSchemaSets(String) *//* www . ja v a2s . c om*/ @Override public List<SchemaSet> getSchemaSets(String userName) { // Get the ID of 'Name' attribute beforehand. int nameAttrId = getJdbcTemplate() .queryForInt("select M_ATTRIBUTE_ID from M_ATTRIBUTE where SHORT_NAME='Name'"); // Now build the main sql, joining to ATTRIBUTE table via above-found ID of 'Name'. StringBuilder sql = new StringBuilder() .append("select SCHEMA_SET_ID, IDENTIFIER, CONTINUITY_ID, REG_STATUS, WORKING_COPY, ") .append("WORKING_USER, DATE_MODIFIED, USER_MODIFIED, COMMENT, CHECKEDOUT_COPY_ID, STATUS_MODIFIED "); if (nameAttrId > 0) { sql.append(",ATTRIBUTE.VALUE as NAME "); } sql.append("from T_SCHEMA_SET "); Map<String, Object> params = new HashMap<String, Object>(); if (nameAttrId > 0) { sql.append("left outer join ATTRIBUTE on ").append( "(T_SCHEMA_SET.SCHEMA_SET_ID=ATTRIBUTE.DATAELEM_ID and ATTRIBUTE.PARENT_TYPE=:attrParentType ") .append("and ATTRIBUTE.M_ATTRIBUTE_ID=:nameAttrId) "); params.put("attrParentType", DElemAttribute.ParentType.SCHEMA_SET.toString()); params.put("nameAttrId", nameAttrId); } sql.append("where "); if (StringUtils.isBlank(userName)) { sql.append("WORKING_COPY=FALSE "); // sql.append("(WORKING_COPY=FALSE and REG_STATUS = :regStatus) "); // params.put("regStatus", SchemaSet.RegStatus.RELEASED.toString()); } else { sql.append("(WORKING_COPY=FALSE or WORKING_USER=:workingUser) "); params.put("workingUser", userName); } // Working copy is added to "order by" so that a working copy always comes after the original when the result list is // displeyd to the user. sql.append("order by ifnull(NAME,IDENTIFIER), SCHEMA_SET_ID"); // Execute the main SQL, build result list. List<SchemaSet> items = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<SchemaSet>() { @Override public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException { SchemaSet ss = new SchemaSet(); ss.setId(rs.getInt("SCHEMA_SET_ID")); ss.setIdentifier(rs.getString("IDENTIFIER")); ss.setContinuityId(rs.getString("CONTINUITY_ID")); ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS"))); ss.setWorkingCopy(rs.getBoolean("WORKING_COPY")); ss.setWorkingUser(rs.getString("WORKING_USER")); ss.setDateModified(rs.getTimestamp("DATE_MODIFIED")); ss.setUserModified(rs.getString("USER_MODIFIED")); ss.setComment(rs.getString("COMMENT")); ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID")); String name = rs.getString("NAME"); if (StringUtils.isNotBlank(name)) { ss.setAttributeValues( Collections.singletonMap("Name", Collections.singletonList(name))); } ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED")); return ss; } }); return items; }
From source file:dsd.dao.ParametersDAO.java
public static List<Parameter> GetParameterHistory(long parameterID) { try {/*from w w w .jav a 2 s.c o m*/ Connection con = DAOProvider.getDataSource().getConnection(); ArrayList<Parameter> parametersList = new ArrayList<Parameter>(); try { Object[] parameters = new Object[1]; parameters[0] = new Long(parameterID); ResultSet results = DAOProvider.SelectTableSecure( // table part tableNameParameters + " join " + tableNameParameterData + " on " + tableNameParameters + ".ID = " + tableNameParameterData + "." + tableParameterDataFields[0], // select part tableNameParameterData + "." + "ID" + " as " + tableNameParameterData + "_" + "ID" + ", " + tableNameParameterData + "." + tableParameterDataFields[0] + " as " + tableNameParameterData + "_" + tableParameterDataFields[0] + ", " + tableNameParameterData + "." + tableParameterDataFields[1] + " as " + tableNameParameterData + "_" + tableParameterDataFields[1] + ", " + tableNameParameterData + "." + tableParameterDataFields[2] + " as " + tableNameParameterData + "_" + tableParameterDataFields[2] + ", " + tableNameParameterData + "." + tableParameterDataFields[3] + " as " + tableNameParameterData + "_" + tableParameterDataFields[3] + ", " + "parameters.* ", // where part " parameters_id = ? ", // order by part "", con, parameters); while (results.next()) { Parameter parameter = new Parameter(); parameter.setParameterID(results.getLong("ID")); parameter.setAbbreviation(results.getString(tableParametersFields[1])); parameter.setCategory( eParameterCategory.getParameterCategory(results.getInt(tableParametersFields[4]))); parameter.setName(results.getString(tableParametersFields[0])); parameter.setParameterDataID(results.getLong(tableNameParameterData + "_ID")); parameter.setTimestamp(results .getTimestamp(tableNameParameterData + "_" + tableParameterDataFields[3]).getTime()); parameter.setUnit(results.getString(tableParametersFields[2])); parameter.setUserID(results.getInt(tableNameParameterData + "_" + tableParameterDataFields[2])); parameter .setValue(results.getFloat(tableNameParameterData + "_" + tableParameterDataFields[1])); parametersList.add(parameter); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); return parametersList; } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:com.threecrickets.prudence.cache.SqlCache.java
public CacheEntry fetch(String key) { Lock lock = lockSource.getReadLock(key); lock.lock();/*w ww . jav a2 s . c o m*/ try { Connection connection = connect(); if (connection == null) return null; try { String sql = "SELECT data, media_type, language, character_set, encoding, modification_date, tag, headers, expiration_date, document_modification_date FROM " + cacheTableName + " WHERE key=?"; PreparedStatement statement = connection.prepareStatement(sql); try { statement.setString(1, key); ResultSet rs = statement.executeQuery(); try { if (rs.next()) { byte[] data = rs.getBytes(1); MediaType mediaType = MediaType.valueOf(rs.getString(2)); Language language = Language.valueOf(rs.getString(3)); CharacterSet characterSet = CharacterSet.valueOf(rs.getString(4)); Encoding encoding = Encoding.valueOf(rs.getString(5)); Timestamp modificationDate = rs.getTimestamp(6); String tagValue = rs.getString(7); Tag tag = tagValue != null ? Tag.parse(tagValue) : null; String rawHeaders = rs.getString(8); Series<Header> headers = (rawHeaders != null) && (rawHeaders.length() > 0) ? deserializeHeaders(rawHeaders) : null; Timestamp expirationDate = rs.getTimestamp(9); Timestamp documentModificationDate = rs.getTimestamp(10); logger.fine("Fetched: " + key); CacheEntry entry; if (encoding != null) entry = new CacheEntry(data, mediaType, language, characterSet, encoding, headers, modificationDate, tag, expirationDate, documentModificationDate); else { try { entry = new CacheEntry(new String(data), mediaType, language, characterSet, null, headers, modificationDate, tag, expirationDate, documentModificationDate); } catch (IOException x) { throw new RuntimeException("Should never happen if data is not encoded!"); } } if (new java.util.Date().after(entry.getExpirationDate())) { lock.unlock(); try { logger.fine("Stale entry: " + key); delete(connection, key); // (Note that this also discarded our lock, // but we kept it as a local variable) } finally { lock.lock(); } return null; } return entry; } } finally { rs.close(); } } finally { statement.close(); } } finally { connection.close(); } } catch (SQLException x) { logger.log(Level.WARNING, "Could not fetch cache entry", x); } finally { lock.unlock(); } logger.fine("Did not fetch: " + key); return null; }