Search code examples
grailsgrails-ormhsqldb

Grails Executing a query


I have a table I make in my app known as Meeting. In Meeting you can choose two people to meet, a string date, and a string location. I want to display the Meetings for each individual coming up soon. So on the index page I have a controller

package collegenowapp

import collegenowapp.Meeting
import org.springframework.security.access.annotation.Secured

@Secured(['ROLE_ADMIN', 'ROLE_COORDINATOR', 'ROLE_LIAISON'])
class IndexController {

def index() { 
        def sql = "select * from Meeting"
        def results = Meeting.executeQuery(sql);
        [results:results]
}
}

Then in the index.gsp I use this

<%-- The list for meeting --%>
<ul>
    <g:each in="${results}" var="result">
        <li>${result}</li>
    </g:each>
</ul>

The page gives me an error saying the * is not allowed, I switch it to the word "date" and then the whole page doesn't work. What am I doing wrong?


Solution

  • you are doing the GORM call wrong:

    def springSecurityService
    
    def index() { 
      def loggedIn = springSecurityService.currentUser
      def results = Meeting.findAllByUser loggedIn, params
      [results:results]
    }