Friday, October 22, 2010

JDBC how to find out if a certain value is in a ResultSet?

Hey all, I have retrieved all the account ids from an Account table and put them in a ResultSet. So,

is there a way to compare an integer value to a ResultSet to see if the integer matches one of the values in the ResultSet? i.e. is the given ID within that table?

Any help is greatly appreaciated!JDBC how to find out if a certain value is in a ResultSet?
you save the output table of ResultSet in an array of string.

so you have to convert the string into integer using Integer class method.

then you can easily compare the both and get your answer u want.JDBC how to find out if a certain value is in a ResultSet?
ResultSet rs = null;

int target = -1;

try {

while(rs.next()) {

if(target == Integer.parseInt(rs.getString(';%26lt;Column Name%26gt;';))) {

//process

}



}

} catch (SQLException e) {

e.printStackTrace();

}

No comments:

Post a Comment