mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
enhance jdbc utils
This commit is contained in:
@@ -40,6 +40,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
|
||||
@@ -543,6 +545,16 @@ public final class JdbcUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static int executeUpdate(DataSource dataSource, String sql, List<Object> parameters) throws SQLException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = dataSource.getConnection();
|
||||
return executeUpdate(conn, sql, parameters);
|
||||
} finally {
|
||||
close(conn);
|
||||
}
|
||||
}
|
||||
|
||||
public static int executeUpdate(Connection conn, String sql, List<Object> parameters) throws SQLException {
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
@@ -560,6 +572,16 @@ public final class JdbcUtils {
|
||||
return updateCount;
|
||||
}
|
||||
|
||||
public static void execute(DataSource dataSource, String sql, List<Object> parameters) throws SQLException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = dataSource.getConnection();
|
||||
execute(conn, sql, parameters);
|
||||
} finally {
|
||||
close(conn);
|
||||
}
|
||||
}
|
||||
|
||||
public static void execute(Connection conn, String sql, List<Object> parameters) throws SQLException {
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
@@ -574,6 +596,17 @@ public final class JdbcUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> executeQuery(DataSource dataSource, String sql, List<Object> parameters)
|
||||
throws SQLException {
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = dataSource.getConnection();
|
||||
return executeQuery(conn, sql, parameters);
|
||||
} finally {
|
||||
close(conn);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> executeQuery(Connection conn, String sql, List<Object> parameters)
|
||||
throws SQLException {
|
||||
List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
|
||||
|
||||
Reference in New Issue
Block a user