posts - 431,  comments - 344,  trackbacks - 0
          公告
           Don't Repeat Yourself
          座右銘:you can lose your money, you can spent all of it, and if you work hard you get it all back. But if you waste your time, you're never gonna get it back.
          公告本博客在此聲明部分文章為轉(zhuǎn)摘,只做資料收集使用。


          微信: szhourui
          QQ:109450684
          Email
          lsi.zhourui@gmail.com
          <2008年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          留言簿(15)

          隨筆分類(1019)

          文章分類(3)

          文章檔案(21)

          收藏夾

          Link

          好友博客

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 865492
          • 排名 - 44

          最新評(píng)論

          閱讀排行榜

           

          在特殊情況下,grails應(yīng)用需要調(diào)用數(shù)據(jù)庫(kù)的存儲(chǔ)過(guò)程,這在grails的官方文檔里邊好像沒(méi)有提到過(guò),在jamesblog里介紹如何解決這個(gè)問(wèn)題。
             
          代碼轉(zhuǎn)貼如下

          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. }  

           需要說(shuō)明的一些是:grails本身沒(méi)有提供訪問(wèn)存儲(chǔ)過(guò)程的便捷方法,而groovyGSQL提供了,因此grails可以直接拿過(guò)來(lái)用了,當(dāng)然也可以用springJdbcTemplate
           
          希望對(duì)grails用戶有點(diǎn)用。

          原文地址:http://grails.group.javaeye.com/group/blog/86666



          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=" org.apache.commons.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-says.blogspot.com/2007/03/grails-little-of-spring-framework.html

          posted on 2008-07-18 09:30 周銳 閱讀(601) 評(píng)論(0)  編輯  收藏 所屬分類: Groovy&Grails
          主站蜘蛛池模板: 南阳市| 柘城县| 吉水县| 海兴县| 西丰县| 鹰潭市| 嵊州市| 深州市| 望谟县| 正镶白旗| 永安市| 孝昌县| 永宁县| 枞阳县| 和政县| 阳春市| 巫山县| 贵港市| 兰州市| 合作市| 罗田县| 阳春市| 浦城县| 肥东县| 静安区| 甘肃省| 阳东县| 葫芦岛市| 青阳县| 辽宁省| 红河县| 阿拉善盟| 梅河口市| 北流市| 涞水县| 洪泽县| 什邡市| 彭阳县| 绍兴市| 栾川县| 定安县|