在特殊情况下,grails应用需要调用数据库的存储过程,这在grails的官方文档里边好像没有提到过,在
james的blog里介绍如何解决这个问题。
代码转贴如下
需要说明的一些是:grails本身没有提供访问存储过程的便捷方法,而groovy的
GSQL提供了,因此grails可以直接拿过来用了,当然也可以用spring的JdbcTemplate。
希望对grails用户有点用。
2006-06-06 update:
对Oracle等支持out/inout类型的stored procedure处理,示例代码如下:
test存储过程第二参数是out类型的变量,对这样out类型处理就是利用sql.call的cloure,如上例所示,另外对inout类型需要用
代码转贴如下
java 代码
- class MainController {
- def dataSource // using the datasource we define in the spring's resources.xml
- def index = {
- Sql sql = new Sql(dataSource)
- def row = sql.execute("call create_daily_hours(${new Date()+1})")
- }
- }
希望对grails用户有点用。
2006-06-06 update:
对Oracle等支持out/inout类型的stored procedure处理,示例代码如下:
java 代码
- Sql sql = new Sql(dataSource)
- sql.call("call test(?,?)",["111",Sql.VARCHAR]) {
- println it+"call"
- }
Sql.inout(Sql.VARCHAR(foo))处理