Sargsyan Grigor
Sargsyan Grigor

Reputation: 579

How to get one int value from an object of type ResultSet?

My code looks like this:

PreparedStatement ask = connectionToSql.prepareStatement("SELECT COUNT(*) FROM tableName");
ResultSet result = ask.executeQuery();

So the result object will only have one int, Integer or any other type of value, won't it? How can I get it?

Upvotes: 1

Views: 1371

Answers (2)

Mureinik
Mureinik

Reputation: 311458

You could use the getInt(int) method:

if (result.next()) { // just in case
    int count = result.getInt(1); // note that indexes are one-based
}

Upvotes: 5

Sukrut Bam
Sukrut Bam

Reputation: 87

you can get the value in this way. Integer a = result.getInt(1);

Upvotes: 1

Related Questions