浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

groovy execute

Sql (groovy 2.0.1 API)

execute

public boolean execute(GString gstring)
                throws java.sql.SQLException
Executes the given SQL with embedded expressions inside. Also saves the updateCount, if any, for subsequent examination.

Example usage:

 def scott = [firstname: "Scott", lastname: "Davis", id: 5, location_id: 50]
 sql.execute """
     insert into PERSON (id, firstname, lastname, location_id) values ($scott.id, $scott.firstname, $scott.lastname, $scott.location_id)
 """
 assert sql.updateCount == 1
 

Resource handling is performed automatically where appropriate.

Parameters:
gstring - a GString containing the SQL query with embedded params
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
expand(Object)
posted on 2012-08-06 17:18  lexus  阅读(1036)  评论(0)    收藏  举报