tags:

views:

52

answers:

1

I have this insert command where iam trying to insert a number to be taken from loop

i=0
for line in column:
    myStmt.executeQuery("INSERT INTO REVERSE_COL
( TABLE_NAME,COL_NAME,POS) values 
(,'test','"+column[i]+"','"+i+"'")
i=i+1

POS IS NUMBER DATATYPE

but it works if i hard code as 1

i=0
for line in column:
    myStmt.executeQuery("INSERT INTO REVERSE_COL
( TABLE_NAME,COL_NAME,POS) values 
(,'test','"+column[i]+"',1")

I have tried only i , +i+ and other method but its not working any suggestion how to solve this .

Thanks everyone .

A: 

I have no jython experience, but I will still try to offer my personal approach and advice. Take from it what you will.

The first thing that I would look into, and perhaps this is something someone else knows offhand, is the way that a number is concatenated to the string. I'm speaking from a C++ background here, but a number i may well be converted to the ASCII character representing that value, and not necessarily the character that you intend.

For example, if i is 9, it may be placing a TAB into the string and not the number 9, which would be an ASCII value 57.

Again, I'm not telling you this IS the answer...but it's the first thing that pops into my mind. Good luck!

KevenK
I had a minute during lunch to look around a bit, and I believe this is likely the case. You didn't mention if the "not working" involved receiving an error, or simply invalid data. But I'm guessing it's the former. Please see http://en.wikibooks.org/wiki/Python_Programming/Variables_and_Strings#Combining_Numbers_and_Strings for informationYou may need to use the `str()` function.
KevenK
Keven, The error was related to Invalid number since the target column has a datatype of number and i have specified in the question too moroever over when using +i+ is being in string and i have tried int(str(+i+) too but nothing seems to work
kdev
By using `int()` around your `str()` you're effectively *cancelling* the function's result. You're converting it from a number, to a string, and back into a number. It seems from here that you specifically need to use `... + column[i] + "','" + str(i) + "'")` at the end of your query.
KevenK
awesome thanks it worked. I was just with the impression that since my target column is number how will str() will go , i was wrong. Thanks for your help
kdev