mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复SqlExecutor.execute执行ORACLE insert into select报ORA-00933问题
This commit is contained in:
parent
5c510bf8b1
commit
791ba35ba0
@ -32,6 +32,7 @@
|
|||||||
* 【cron 】 修复SystemTimer无法结束进程问题(issue#3090@Github)
|
* 【cron 】 修复SystemTimer无法结束进程问题(issue#3090@Github)
|
||||||
* 【core 】 修复BeanUtil.copyToList复制Long等类型错误问题(issue#3091@Github)
|
* 【core 】 修复BeanUtil.copyToList复制Long等类型错误问题(issue#3091@Github)
|
||||||
* 【poi 】 修复MapRowHandler结果Map无序问题(issue#I71SE8@Github)
|
* 【poi 】 修复MapRowHandler结果Map无序问题(issue#I71SE8@Github)
|
||||||
|
* 【db 】 修复SqlExecutor.execute执行ORACLE insert into select报ORA-00933问题(issue#I778U7@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.18 (2023-04-27)
|
# 5.8.18 (2023-04-27)
|
||||||
|
@ -124,6 +124,21 @@ public class StatementUtil {
|
|||||||
* @since 3.2.3
|
* @since 3.2.3
|
||||||
*/
|
*/
|
||||||
public static PreparedStatement prepareStatement(Connection conn, String sql, Object... params) throws SQLException {
|
public static PreparedStatement prepareStatement(Connection conn, String sql, Object... params) throws SQLException {
|
||||||
|
return prepareStatement(GlobalDbConfig.returnGeneratedKey, conn, sql, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建{@link PreparedStatement}
|
||||||
|
*
|
||||||
|
* @param returnGeneratedKey 当为insert语句时,是否返回主键
|
||||||
|
* @param conn 数据库连接
|
||||||
|
* @param sql SQL语句,使用"?"做为占位符
|
||||||
|
* @param params "?"对应参数列表
|
||||||
|
* @return {@link PreparedStatement}
|
||||||
|
* @throws SQLException SQL异常
|
||||||
|
* @since 5.8.19
|
||||||
|
*/
|
||||||
|
public static PreparedStatement prepareStatement(boolean returnGeneratedKey, Connection conn, String sql, Object... params) throws SQLException {
|
||||||
Assert.notBlank(sql, "Sql String must be not blank!");
|
Assert.notBlank(sql, "Sql String must be not blank!");
|
||||||
sql = sql.trim();
|
sql = sql.trim();
|
||||||
|
|
||||||
@ -136,7 +151,7 @@ public class StatementUtil {
|
|||||||
|
|
||||||
SqlLog.INSTANCE.log(sql, ArrayUtil.isEmpty(params) ? null : params);
|
SqlLog.INSTANCE.log(sql, ArrayUtil.isEmpty(params) ? null : params);
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
if (GlobalDbConfig.returnGeneratedKey && StrUtil.startWithIgnoreCase(sql, "insert")) {
|
if (returnGeneratedKey && StrUtil.startWithIgnoreCase(sql, "insert")) {
|
||||||
// 插入默认返回主键
|
// 插入默认返回主键
|
||||||
ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||||
} else {
|
} else {
|
||||||
|
@ -54,7 +54,7 @@ public class SqlExecutor {
|
|||||||
public static int execute(Connection conn, String sql, Object... params) throws SQLException {
|
public static int execute(Connection conn, String sql, Object... params) throws SQLException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
ps = StatementUtil.prepareStatement(conn, sql, params);
|
ps = StatementUtil.prepareStatement(false, conn, sql, params);
|
||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} finally {
|
} finally {
|
||||||
DbUtil.close(ps);
|
DbUtil.close(ps);
|
||||||
@ -128,7 +128,7 @@ public class SqlExecutor {
|
|||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
ps = StatementUtil.prepareStatement(conn, sql, params);
|
ps = StatementUtil.prepareStatement(true, conn, sql, params);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
rs = ps.getGeneratedKeys();
|
rs = ps.getGeneratedKeys();
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
@ -271,7 +271,7 @@ public class SqlExecutor {
|
|||||||
public static <T> T query(Connection conn, String sql, RsHandler<T> rsh, Object... params) throws SQLException {
|
public static <T> T query(Connection conn, String sql, RsHandler<T> rsh, Object... params) throws SQLException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
ps = StatementUtil.prepareStatement(conn, sql, params);
|
ps = StatementUtil.prepareStatement(false, conn, sql, params);
|
||||||
return executeQuery(ps, rsh);
|
return executeQuery(ps, rsh);
|
||||||
} finally {
|
} finally {
|
||||||
DbUtil.close(ps);
|
DbUtil.close(ps);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user