将Groovy SQL结果存储为变量?

时间:2017-09-26 18:47:44

标签: sql email variables groovy

我对Groovy非常非常新(比如两天)。我试图获取一个SQL结果,它将返回一个值,并存储该值,以便它可以放在电子邮件的正文中。但是,我的SQL结果总是返回NULL,但电子邮件中的其他值工作正常。

我知道结果只会返回一个值,那么我怎样才能将该值存储为字符串?

def sql = getSqlInstance()
def user = "\'" + trmCurrentUser.username + "\'";
def name = "\'" + trmCurrentUser.displayname + "\'";
def email = "\'" + trmCurrentUser.email + "\'";
def comm = "\'" + trmComponent.id + "\'";
def rslt=[];
def cmpgn;

rslt[0] = sql.firstRow("select activity_id from DB.TABLE where communication_id=${comm}");
def cmpgn = rslt[0];

toAddress = trmCurrentUser.email;
fromAddress = "me@email.com";

trmUtilities.sendEmail (
//self explanatory
toAddress, fromAddress,

//body of email
user + " " + name + " " + email + " " + comm + " " + cmpgn[0],

//subject of email
 " Action on " + trmComponent.componentType + " " + trmComponent.name
);

我得到的结果是这个(使用除NULL以外的适当值): ' MYID' '我的名字' ' MYEMAIL' ' COMM'空

0 个答案:

没有答案