Close context in a finally

This commit is contained in:
Travis Burtrum 2017-04-20 10:28:32 -04:00
parent a7e159b172
commit 6bcb3d0039
1 changed files with 10 additions and 9 deletions

View File

@ -33,15 +33,16 @@ public class QueryMapper implements Closeable {
this.cm = cm == null ? new ResultSetMapper() : cm;
Context context = null;
if (conn == null && jndiName != null)
try {
context = new InitialContext();
DataSource ds = (DataSource) context.lookup(jndiName);
conn = ds.getConnection();
} catch (Throwable e) {
e.printStackTrace();
tryClose(conn);
tryClose(context);
}
try {
context = new InitialContext();
DataSource ds = (DataSource) context.lookup(jndiName);
conn = ds.getConnection();
} catch (Throwable e) {
e.printStackTrace();
tryClose(conn);
} finally {
tryClose(context);
}
this.conn = conn;
this.context = context;
if (this.conn == null)