Close context in a finally
This commit is contained in:
parent
a7e159b172
commit
6bcb3d0039
@ -33,15 +33,16 @@ public class QueryMapper implements Closeable {
|
|||||||
this.cm = cm == null ? new ResultSetMapper() : cm;
|
this.cm = cm == null ? new ResultSetMapper() : cm;
|
||||||
Context context = null;
|
Context context = null;
|
||||||
if (conn == null && jndiName != null)
|
if (conn == null && jndiName != null)
|
||||||
try {
|
try {
|
||||||
context = new InitialContext();
|
context = new InitialContext();
|
||||||
DataSource ds = (DataSource) context.lookup(jndiName);
|
DataSource ds = (DataSource) context.lookup(jndiName);
|
||||||
conn = ds.getConnection();
|
conn = ds.getConnection();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
tryClose(conn);
|
tryClose(conn);
|
||||||
tryClose(context);
|
} finally {
|
||||||
}
|
tryClose(context);
|
||||||
|
}
|
||||||
this.conn = conn;
|
this.conn = conn;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
if (this.conn == null)
|
if (this.conn == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user