ETC

[Groovy] SQL 사용 방법

1984 2022. 10. 3. 17:24

 

def delegator = (DelegatorInterface) Component.Accessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default")

Connection conn = ConnectionFactory.getConnection(helperName)
Sql sql = new Sql(conn)

def sqlStmt = "select * from table"

try{
    sql.eachRow(sqlStmt){
        user -> log.debug(user)
    }
}catch{
    
}finally{
    sql.close()
}

 

728x90