所有 sql 输出的一个变量

发布于 2024-08-27 21:30:06 字数 282 浏览 4 评论 0原文

myRs=myStmt.executeQuery("从 tab_col 中选择 i_col,col_name") 我=0 while (myRs.next()): list= myRs.getString("I_COL")+','+myRs.getString("COL_NAME")

我有一个 jython 代码来运行 sql 语句,我想将 sql 的所有行存储到单个变量中。我曾经用列表来存储值,但它总是只存储单行,所以有没有办法追加所有行并继续添加到单个变量。

非常感谢您的帮助。

myRs=myStmt.executeQuery("select i_col,col_name from tab_col")
i=0
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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疾风者 2024-09-03 21:30:06

使用该代码,您可以在 while 循环的每次迭代中覆盖“list”变量(= 是一个赋值),尝试这样的操作(我使用 rs 而不是 >list 以避免与内置函数 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"))

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"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文