`
agile_boy
  • 浏览: 550068 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

grails调用存储过程

阅读更多
  在特殊情况下,grails应用需要调用数据库的存储过程,这在grails的官方文档里边好像没有提到过,在james的blog里介绍如何解决这个问题。
    代码转贴如下
java 代码
 
  1. class MainController {  
  2.   
  3.   def dataSource // using the datasource we define in the spring's resources.xml  
  4.   
  5.   def index = {  
  6.       Sql sql = new Sql(dataSource)  
  7.       def row = sql.execute("call create_daily_hours(${new Date()+1})")  
  8.   }  
  9. }  
  需要说明的一些是:grails本身没有提供访问存储过程的便捷方法,而groovy的GSQL提供了,因此grails可以直接拿过来用了,当然也可以用spring的JdbcTemplate。
  希望对grails用户有点用。

  2006-06-06 update:
 对Oracle等支持out/inout类型的stored procedure处理,示例代码如下:
java 代码
 
  1. Sql sql = new Sql(dataSource)  
  2.             sql.call("call test(?,?)",["111",Sql.VARCHAR]) {  
  3.                 println it+"call"  
  4.             }  
  test存储过程第二参数是out类型的变量,对这样out类型处理就是利用sql.call的cloure,如上例所示,另外对inout类型需要用
Sql.inout(Sql.VARCHAR(foo))处理
分享到:
评论
3 楼 山风小子 2007-06-04  
agile_boy,你多虑了
2 楼 agile_boy 2007-06-04  
呵呵,我还没有自己写代码验证过,不过理论上是没有问题的,在controller里边可以直接引用dataSource及其他的spring服务,而且grails是基于groovy的,GSQL那样用法应该问题也不大
1 楼 山风小子 2007-06-04  
很有用,转载一下,以备後用

相关推荐

Global site tag (gtag.js) - Google Analytics