收藏 分销(赏)

[转载]grails调用存储过程(Grails:-calling-a-stored-procedure).doc

上传人:仙人****88 文档编号:7380023 上传时间:2025-01-01 格式:DOC 页数:2 大小:25.50KB 下载积分:10 金币
下载 相关 举报
[转载]grails调用存储过程(Grails:-calling-a-stored-procedure).doc_第1页
第1页 / 共2页
[转载]grails调用存储过程(Grails:-calling-a-stored-procedure).doc_第2页
第2页 / 共2页
本文档共2页,全文阅读请下载到手机保存,查看更方便
资源描述
[转载]grails调用存储过程(Grails : calling a stored procedure)   在特殊情况下,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用户有点用。 原文地址: My experience with grails is getting richer the longer I use it for web application developing. It's very nice that grails is built on top of spring framework which we can take advantage of. I am not a spring user before but with a help from the nice people at the grails forum I was able to achieve what I want to do. Calling a stored procedure from a MySQL database or any other database is simple. First we need a datasource which spring could provide for us. I have the following code place in the resources.xml found in the spring folder in your grails folder. <bean id="dataSource" class=" mons.dbcp.BasicDataSource "> <property name="driverClassName"> <value>org.hsqldb.jdbcDriver</value> </property> <property name="url"> <value>jdbc:hsqldb:hsql://localhost</value> </property> <property name="username"> <value>sa</value> </property> <property name="password"> <value></value> </property> </bean> I use connection pooling for better performance. In my controller here is how I use the datasource to call a store procedure. 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})") } } That's it! Notice that I am using Groovy SQL instead of Spring JDBCTemplate. It's a lot more friendlier for a beginner. Grails really makes everything easy here and provides a lot of flexibility thanks to it's nice integration with spring. From here everything is possible. 原文地址:http://james- 附:朝花夕拾——Groovy & Grails posted on 2007-06-04 19:39 山风小子
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服