|
|
@@ -55,12 +55,18 @@ public class SqlServiceImpl implements SqlService {
|
|
|
try(Connection conn = DriverManager.getConnection(dbUrl, username, password);
|
|
|
Statement stmt = conn.createStatement();
|
|
|
) {
|
|
|
+ //为了支持学生trigger特殊写法
|
|
|
+ if (sql.length()>=14 && "trigger".equals(sql.substring(7,14))){
|
|
|
+ stmt.execute(sql);
|
|
|
+ return "Success";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//select query desc走query 其他走update
|
|
|
String prefix = sql.substring(0, sql.indexOf(" ")).toLowerCase(Locale.ROOT);
|
|
|
-
|
|
|
if ("select".equals(prefix) || "show".equals(prefix) || "desc".equals(prefix)){
|
|
|
ResultSet rs = stmt.executeQuery(sql);
|
|
|
- return "Boolean\n"+ convertResultSet2List(rs);
|
|
|
+ return "Success\n"+ convertResultSet2List(rs);
|
|
|
} else {
|
|
|
//batch执行,注意;不要用于
|
|
|
if (sql.contains(";")){
|
|
|
@@ -69,17 +75,17 @@ public class SqlServiceImpl implements SqlService {
|
|
|
stmt.addBatch(tmp);
|
|
|
}
|
|
|
int[] res = stmt.executeBatch();
|
|
|
- return "Boolean\nAffected :"+ Arrays.toString(res);
|
|
|
+ return "Success\nAffected :"+ Arrays.toString(res);
|
|
|
} else {
|
|
|
int i = stmt.executeUpdate(sql);
|
|
|
- return "Boolean\nAffected :"+i;
|
|
|
+ return "Success\nAffected :"+i;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("url: {}\nsql: {}\nsql state: {}", dbUrl,sql,e.getMessage());
|
|
|
- return "False\n"+e.getMessage();
|
|
|
+ return "Fail\n"+e.getMessage();
|
|
|
}
|
|
|
|
|
|
}
|