使用以下内容
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/eventDb", "user",
"pwd", "com.mysql.jdbc.Driver")
def sqlInsert = "INSERT INTO GTEST (EVENTID,TSTAMP,USER_ID,USER_FIRST_NAME) VALUES (?,?,?,?)"
def sqlParams = ['EVENTID':0, 'TSTAMP':'','USER_ID':'janew','USER_FIRST_NAME':'janewithaverylongnamesothatitdoesntfitwell']
sqlParams['TSTAMP'] = new Date()
sql.withTransaction {stmt ->
def eventId = sql.executeInsert("INSERT INTO EVENTS (LOGID,TSTAMP) VALUES (2,CURRENT_TIMESTAMP)")
sqlParams['EVENTID'] = eventId [0][0]
sql.executeInsert(sqlInsert, sqlParams.values().toList())
}
第二个执行将失败,但第一个插入不会回滚.我在这做错了什么?
解决方法:
你没有显示表格的定义;也许那些是MyISAM,因此不支持交易?