import groovy.sql.Sql;
class YourController {
def dataSource ;
.....
def print = {
.....
def sql = new Sql(dataSource);
List lparams = [startDate, endDate];
def query2 = "select * from invoiceh where trx_date between ? and ? ";
def result = sql.rows(query2,lparams);
...... // fetch the result into your gsp / you can process it further
}
}
本文展示了一个使用Groovy语言进行SQL查询的例子。通过定义一个名为`print`的方法,利用`dataSource`连接数据库并执行参数化的SQL语句,从`invoicehw`表中选取在指定日期范围内的所有记录。
45

被折叠的 条评论
为什么被折叠?



