开发者

one variable for all the sql output

myRs=myStmt.executeQuery("select i_col,col_name from tab_col") i=0 开发者_如何学Python while (myRs.next()): list= myRs.getString("I_COL")+','+myRs.getString("COL_NAME")

i have a jython code to run a sql statement i want to store all the row of the sql into a single variable. I used to list to store the value but its always storing only the single line , so is there is way to append all the rows and keep adding to single variable.

Thanks so much for your help.


With that code you overwrite the "list" variable in every iteration of the while loop (= is an assignment), try something like this (I used rs rather than list to avoid a name clash with the builtin function list()):

myRs=myStmt.executeQuery("select i_col,col_name from tab_col")
rs=[]
i=0
while (myRs.next()):
    rs.append(myRs.getString("I_COL")+','+myRs.getString("COL_NAME"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜