|
|
@@ -1,18 +1,15 @@
|
|
|
package org.dromara.rs.controller;
|
|
|
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.rs.mapper.RsSystemMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import javax.sql.DataSource;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
-import java.sql.Connection;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.sql.Statement;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -27,7 +24,7 @@ import java.util.Map;
|
|
|
public class SqlUpdateController {
|
|
|
|
|
|
@Autowired
|
|
|
- private DataSource dataSource;
|
|
|
+ private RsSystemMapper rsSystemMapper;
|
|
|
|
|
|
/**
|
|
|
* 执行培训模块SQL更新脚本
|
|
|
@@ -57,7 +54,10 @@ public class SqlUpdateController {
|
|
|
|
|
|
// 如果是SQL语句结束
|
|
|
if (line.trim().endsWith(";")) {
|
|
|
- String sql = sb.toString();
|
|
|
+ String sql = sb.toString().trim();
|
|
|
+ if (sql.endsWith(";")) {
|
|
|
+ sql = sql.substring(0, sql.length() - 1); // 移除分号,MyBatis会自动处理
|
|
|
+ }
|
|
|
executeSql(sql);
|
|
|
sb = new StringBuilder();
|
|
|
}
|
|
|
@@ -77,16 +77,12 @@ public class SqlUpdateController {
|
|
|
/**
|
|
|
* 执行单条SQL语句
|
|
|
*/
|
|
|
- private void executeSql(String sql) throws SQLException {
|
|
|
- try (Connection conn = dataSource.getConnection();
|
|
|
- Statement stmt = conn.createStatement()) {
|
|
|
- // 忽略SQL错误(如字段已存在)
|
|
|
+ private void executeSql(String sql) {
|
|
|
try {
|
|
|
- stmt.execute(sql);
|
|
|
- } catch (SQLException e) {
|
|
|
+ rsSystemMapper.executeSql(sql);
|
|
|
+ } catch (Exception e) {
|
|
|
// 记录错误但继续执行
|
|
|
System.out.println("SQL执行警告: " + e.getMessage());
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|