Mysql Spring模板:如何执行多个SQL语句?
我想执行一些SQL代码(在MySQL上)如下所示(它不是存储过程): 如何使用Spring模板来实现它? 当我尝试使用JdbcTemplate时,Spring似乎不理解这个查询 在使用Spring模板时,是否不允许从SQL代码启动事务Mysql Spring模板:如何执行多个SQL语句?,mysql,sql,spring,transactions,spring-jdbc,Mysql,Sql,Spring,Transactions,Spring Jdbc,我想执行一些SQL代码(在MySQL上)如下所示(它不是存储过程): 如何使用Spring模板来实现它? 当我尝试使用JdbcTemplate时,Spring似乎不理解这个查询 在使用Spring模板时,是否不允许从SQL代码启动事务 当使用Spring模板时,我可以从SQL代码启动事务吗?当使用存储过程时?看看SpringTransactionTemplate,这是在使用JDBC模板时执行事务的最佳方法(请参见此处): START TRANSACTION; INSERT...; SELE
当使用Spring模板时,我可以从SQL代码启动事务吗?当使用存储过程时?看看Spring
TransactionTemplate
,这是在使用JDBC模板时执行事务的最佳方法(请参见此处):
START TRANSACTION;
INSERT...;
SELECT...;
COMMIT;
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
jdbcTemplate.update("INSERT INTO PERSON (FIRSTNAME, LASTNAME) VALUES(?,?)",
new Object[] { firstName, lastName });
... multiple calls to JDBC template, all inside the same transaction ....
}
});