I am reading a col. from a table... but it gives java.sql.SQLException: Invalid column index runtime sql exception
ResultSet resultset = statement.executeQuery("select PIN,TESTTYPE from TestUser where PIN='" + s + "'"); System.out.println("IN IFFFFFFFFFFFFFF"); while(resultset.next()) { s2 = resultset.getString(9); System.out.println(s2); ttype = resultset.getString(5); System.out.println(ttype); }
resultset.close(); statement.close();
A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Why 9 and 5?
There is no emoticon for what I am feeling!
Maximilian Xavier Stocker
Ranch Hand
Joined: Sep 20, 2005
Posts: 381
posted
0
Errr yes as mentioned you are selecting two columns and then trying to get columns 9 and 5 which don't exist in that result set. You should be getting columns 1 and 2. (Remember result set column indexing begins at 1 not zero!)
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Again, the column numbering (starting with 1 :roll: ) is in respect to the SELECT statement's field list, not the db's ordering of the columns on your table You should never write SQL that relies on the table's column ordering, because it is easy for your DBA to alter that ordering as he goes about his job :roll: [ December 16, 2005: Message edited by: Jeff Albrechtsen ]
Maximilian Xavier Stocker
Ranch Hand
Joined: Sep 20, 2005
Posts: 381
posted
0
Originally posted by Jeff Albrechtsen: Again, the column numbering (starting with 1 :roll: ) is in respect to the SELECT statement's field list, not the db's ordering of the columns on your table You should never write SQL that relies on the table's column ordering, because it is easy for your DBA to alter that ordering as he goes about his job :roll:
[ December 16, 2005: Message edited by: Jeff Albrechtsen ]
I don't understand this post at all.
There is a lot of :roll: and I am not sure for whom or what. The original query has the field names specified. If it was * then I could understand. Also I addressed the columns specifically as result set columns in my post.
I mean if you are saying that doing x (in this case explictly naming your columns in SELECT) is a good practice okay. But that is what we are doing. I just don't get the :roll:
M. Dooze
Greenhorn
Joined: Oct 29, 2007
Posts: 6
posted
0
but you have made it even a more by adding two extra ones...so now there's a whooooping count of 5 count of with one looking uninterested and sort of shocked at how its friends are bling blinging...
i cant remove the quote because datatype is varchar..
Little misunderstanding. You must not use single quotes with the dynamic parameters (?) of a prepared statement. They will be automatically added for varchars (or other kind of string types).
i cant remove the quote because datatype is varchar..
Little misunderstanding. You must not use single quotes with the dynamic parameters (?) of a prepared statement. They will be automatically added for varchars (or other kind of string types).