C - object typepublic class Close<C> extends Object
Close:
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
try {
...
} catch (Exception e) {
...
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (st != null) {
try {
st.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use Close:
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
try {
...
} catch (Exception e) {
...
} finally {
Close.close(rs);
Close.close(st);
Close.close(conn);
}
| 限定符 | 构造器 | 说明 |
|---|---|---|
private |
Close() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static <T extends AutoCloseable> |
close(T autoCloseable) |
Closing resources.
|
static <T extends AutoCloseable> |
close(T autoCloseable,
boolean isPrintTrace) |
Closing resources.
|
static <T extends AutoCloseable> |
close(T autoCloseable,
V2<T,Throwable> catchAction) |
Simplify
try-catch-finally block when closing resources. |
static <T extends AutoCloseable> |
close(T autoCloseable,
V2<T,Throwable> catchAction,
V1<T> finallyAction) |
Simplify
try-catch-finally block when closing resources. |
static void |
closeAll(boolean isPrintTrace,
AutoCloseable... autoCloseables) |
Closing multi-resources that
implements AutoCloseable. |
static void |
closeAll(AutoCloseable... autoCloseables) |
Closing multi-resources that
implements AutoCloseable. |
static <T> Close<T> |
of(T t) |
|
void |
tcf(VT1<C,Throwable> closeAction) |
Closing resources that not
implements AutoCloseable. |
void |
tcf(VT1<C,Throwable> closeAction,
boolean isPrintTrace) |
Closing resources that not
implements AutoCloseable. |
void |
tcf(VT1<C,Throwable> closeAction,
V2<C,Throwable> catchAction) |
|
void |
tcf(VT1<C,Throwable> closeAction,
V2<C,Throwable> catchAction,
V1<C> finallyAction) |
public static <T> Close<T> of(T t)
public static <T extends AutoCloseable> void close(T autoCloseable)
T - type of resourcesautoCloseable - resources that implements AutoCloseableclose(AutoCloseable, boolean)public static <T extends AutoCloseable> void close(T autoCloseable, boolean isPrintTrace)
T - type of resourcesautoCloseable - resources that implements AutoCloseableisPrintTrace - isPrintTracepublic static <T extends AutoCloseable> void close(T autoCloseable, V2<T,Throwable> catchAction)
try-catch-finally block when closing resources. T - type of resourcesautoCloseable - resources that implements AutoCloseablecatchAction - catchActionclose(AutoCloseable, V2, V1)public static <T extends AutoCloseable> void close(T autoCloseable, V2<T,Throwable> catchAction, V1<T> finallyAction)
try-catch-finally block when closing resources. T - type of resourcesautoCloseable - resources that implements AutoCloseablecatchAction - catchActionfinallyAction - finallyActionpublic static void closeAll(AutoCloseable... autoCloseables)
autoCloseables - autoCloseablespublic static void closeAll(boolean isPrintTrace,
AutoCloseable... autoCloseables)
isPrintTrace - isPrintTraceautoCloseables - autoCloseablespublic void tcf(VT1<C,Throwable> closeAction)
closeAction - closeActiontcf(VT1, boolean)public void tcf(VT1<C,Throwable> closeAction, boolean isPrintTrace)
closeAction - closeActionisPrintTrace - isPrintTracepublic void tcf(VT1<C,Throwable> closeAction, V2<C,Throwable> catchAction)
try-catch-finally block when closing resources that not implements AutoCloseable. AutoCloseable 接口closeAction - closeActioncatchAction - catchActiontcf(VT1, V2, V1)public void tcf(VT1<C,Throwable> closeAction, V2<C,Throwable> catchAction, V1<C> finallyAction)
try-catch-finally block when closing resources that not implements AutoCloseable. AutoCloseable 接口closeAction - closeActioncatchAction - catchActionfinallyAction - finallyActionCopyright © 2023 io-fairy. All rights reserved.