2012-09-24 2 views

답변

0

Grails 서비스에서이 작업을 수행 할 수 있습니다.

// Inject a data source: 
def dataSource //or def dataSource_<other named DS name> 

def serviceMethod() { 
    Sql sql = new Sql(dataSource_messages) 

    def sqlCall = "exec sp_name :param1, :param2" 
    final paramMap = [param1: new Timestamp(dateFrom.time), param2: new Timestamp(dateTo.time)] 
    log.info "Running: $sqlCall with params $paramMap" 
    def rows = [] 
    try { 
     rows = sql.rows(sqlCall, paramMap) 
    } catch (Exception e) { 
     log.warn "Could not execute ${sqlCall} with params ${paramMap}: ${e.getMessage()}", e 
    } 
    rows 

}

선택적으로

하는 개체를 명령로 변환 :

rows.collect { row -> new MyCmd(row) } 

public class MyCmd { 
    String spField1 
    String spField2 
    Date dateTime 
} 
관련 문제