mirror of
https://gitee.com/huoyo/ko-time.git
synced 2025-12-06 08:48:30 +08:00
optimize the saver of database
This commit is contained in:
parent
c979f7161e
commit
012e7adc0d
@ -32,7 +32,7 @@ public class DataBaseUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int insert(Connection connection, String sql, Object[] values) {
|
public static int insert(Connection connection, String sql, Object[] values) {
|
||||||
PreparedStatement statement;
|
PreparedStatement statement = null;
|
||||||
try {
|
try {
|
||||||
statement = connection.prepareStatement(sql);
|
statement = connection.prepareStatement(sql);
|
||||||
if (null != values) {
|
if (null != values) {
|
||||||
@ -44,6 +44,14 @@ public class DataBaseUtil {
|
|||||||
log.warning("Duplicate id:" + values[0]);
|
log.warning("Duplicate id:" + values[0]);
|
||||||
} catch (SQLException throwables) {
|
} catch (SQLException throwables) {
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (statement != null) {
|
||||||
|
try {
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException throwables) {
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -72,7 +80,7 @@ public class DataBaseUtil {
|
|||||||
|
|
||||||
public static List<Map<String, Object>> query(Connection connection, String sql, Object[] values) {
|
public static List<Map<String, Object>> query(Connection connection, String sql, Object[] values) {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
PreparedStatement statement;
|
PreparedStatement statement = null;
|
||||||
try {
|
try {
|
||||||
statement = connection.prepareStatement(sql);
|
statement = connection.prepareStatement(sql);
|
||||||
if (null != values) {
|
if (null != values) {
|
||||||
@ -90,13 +98,21 @@ public class DataBaseUtil {
|
|||||||
}
|
}
|
||||||
} catch (SQLException throwables) {
|
} catch (SQLException throwables) {
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (statement != null) {
|
||||||
|
try {
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException throwables) {
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> List<T> query(Connection connection, String sql, Object[] values, Class<T> c) {
|
public static <T> List<T> query(Connection connection, String sql, Object[] values, Class<T> c) {
|
||||||
List<T> list = new ArrayList<>();
|
List<T> list = new ArrayList<>();
|
||||||
PreparedStatement statement;
|
PreparedStatement statement = null;
|
||||||
try {
|
try {
|
||||||
statement = connection.prepareStatement(sql);
|
statement = connection.prepareStatement(sql);
|
||||||
if (null != values) {
|
if (null != values) {
|
||||||
@ -139,6 +155,14 @@ public class DataBaseUtil {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (statement != null) {
|
||||||
|
try {
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException throwables) {
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user