您的位置:首页 > 博客中心 > 数据库 >

grails中直接使用SQL语句

时间:2022-03-13 22:51

    在grails中直接使用SQL语句进行查询,可以直接获取一个新连接,也可以使用默认的数据源

    查询代码:    

      ApplicationContext ctx = (ApplicationContext) ApplicationHolder.getApplication().getMainContext()
      def dataSource = ctx.getBean(‘dataSource‘)
      def sql = new Sql(dataSource)
      String strSql = "select * from company"
      sql.eachRow(strSql) {
          println it
          println it.id
      }
      //需要导包
      import groovy.sql.Sql
      import org.codehaus.groovy.grails.commons.ApplicationHolder
      import org.springframework.context.ApplicationContext

    

grails中直接使用SQL语句,布布扣,bubuko.com

热门排行

今日推荐

热门手游