sqlresultsetmapping

Efficient way to Handle ResultSet in Java

与世无争的帅哥 提交于 2019-11-27 17:04:59
I'm using a ResultSet in Java, and am not sure how to properly close it. I'm considering using the ResultSet to construct a HashMap and then closing the ResultSet after that. Is this HashMap technique efficient, or are there more efficient ways of handling this situation? I need both keys and values, so using a HashMap seemed like a logical choice. If using a HashMap is the most efficient method, how do I construct and use the HashMap in my code? Here's what I've tried: public HashMap resultSetToHashMap(ResultSet rs) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int columns =

Efficient way to Handle ResultSet in Java

佐手、 提交于 2019-11-26 18:53:48
问题 I'm using a ResultSet in Java, and am not sure how to properly close it. I'm considering using the ResultSet to construct a HashMap and then closing the ResultSet after that. Is this HashMap technique efficient, or are there more efficient ways of handling this situation? I need both keys and values, so using a HashMap seemed like a logical choice. If using a HashMap is the most efficient method, how do I construct and use the HashMap in my code? Here's what I've tried: public HashMap