diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java index 29a347a7d..23ff0cae4 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java @@ -11,11 +11,18 @@ public class MysqlDBManage extends DefaultDBManage implements DBManage { @Override - public void updateProcedure(Connection connection, String databaseName, String schemaName, Procedure procedure) { - String sql = "DROP PROCEDURE " + procedure.getProcedureName(); - SQLExecutor.getInstance().execute(connection, sql, resultSet -> {}); - String procedureBody = procedure.getProcedureBody(); - SQLExecutor.getInstance().execute(connection, procedureBody, resultSet -> {}); + public void updateProcedure(Connection connection, String databaseName, String schemaName, Procedure procedure) throws SQLException { + try { + connection.setAutoCommit(false); + String sql = "DROP PROCEDURE " + procedure.getProcedureName(); + SQLExecutor.getInstance().execute(connection, sql, resultSet -> {}); + String procedureBody = procedure.getProcedureBody(); + SQLExecutor.getInstance().execute(connection, procedureBody, resultSet -> {}); + connection.commit(); + } catch (Exception e) { + connection.rollback(); + throw new RuntimeException(e); + } } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/DBManage.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/DBManage.java index 90b044384..db039ea75 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/DBManage.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/DBManage.java @@ -7,6 +7,7 @@ import jakarta.validation.constraints.NotNull; import java.sql.Connection; +import java.sql.SQLException; /** * @author jipengfei @@ -119,5 +120,5 @@ void dropProcedure(Connection connection, @NotEmpty String databaseName, String * @param schemaName * @param procedure */ - void updateProcedure(Connection connection, @NotEmpty String databaseName, String schemaName, @NotNull Procedure procedure); + void updateProcedure(Connection connection, @NotEmpty String databaseName, String schemaName, @NotNull Procedure procedure) throws SQLException; } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultDBManage.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultDBManage.java index f5cc641db..bfde05454 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultDBManage.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultDBManage.java @@ -135,7 +135,7 @@ public void dropProcedure(Connection connection, String databaseName, String sch } @Override - public void updateProcedure(Connection connection, String databaseName, String schemaName, Procedure procedure) { + public void updateProcedure(Connection connection, String databaseName, String schemaName, Procedure procedure) throws SQLException { }