tags:

views:

32

answers:

1

hi everyone

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.

A: 

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"))
paprika
Thanks so much it worked. Just another query , if i have to use select * from tab_col , how can i get all the columns . Thanks again for your help
kdev
@kdev: You should ask this in a separate question, it's a whole different topic. Anyway, this might help (assuming your Jython code uses JDBC):http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html#getMetaData%28%29
paprika