I'm using ojdbc8 version 21.1.0.0 to be my JDBC. I have encountered issues that my connection stream will be closed everytime before calling close()
when I execute my query that asked for long from resultSet for unknown reason, and my SQL runs fine on SQL developer. So I googled and see this bug reported on Oracle.
https://support.oracle.com/knowledge/Middleware/832903_1.html
Seem like it's a bug to their JDBCs? Does anyone know which version of ODBC8 doesn't have this bug? or other walkaround to avoid this bug?
==== Update ====
@Stephen C
Well, if you say so. But I don't think this would help anyway since the code itself is too simple to have such bug.
class Channel {
private static DataSource ds = null;
private static final String GET_ONE = "SELECT * FROM Channel WHERE Id=?";
public Channel() {
if(ds == null) {
try {
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("jdbc/oracle");
} catch (NamingException e) {
e.printStackTrace();
}
}
}
public HashMap<String, Object> getOne(String id) throws SQLException{
HashMap<String, Object> result = null;
ResultSet rs = null;
try(Connection conn = ds.getConnection();
PreparedStatement pstmt = con.prepareStatement(GET_ONE);){
pstmt.setString(1, id);
rs = pstmt.executeQuery();
if(rs.next()){
result = new HashMap<String, Object>();
result.put("Time_Limit", rs.getLong("Time_Limit"));// recommended by @tgdavies
result.put("Id", rs.getString("Id"));
result.put("Name", rs.getString("Name"));
}
} catch(SQLException e){
throw e;
} finally {
if(rs != null){
try{
rs.close();
} catch(SQLException e){}
}
}
return result;
}
}