Re: variable in sql query



Anna Kubiak wrote:


thanks i tried , maybe it works or not, because when i use command String name_variable =rs.getString(1) where rs is declared as record set. i wrote prepareStatement(qry) where qry is "Select * from table where name_of_field like ?" When I am testing rs is not empty, but still it seems getString doesn't work (the types are not mixed for sure).

what's maybe the reason?
Thanks, Anna



The ResultSet "pointer" starts before the first returned record. Typically one uses the following to iterate through the result set:

while(rs.next()) {
String name_variable = rs.getString(1);
// do something else
// ...
}

So, just try rs.next() to get to the first record.

--
John O'Conner
.