Java examples for java.sql:ResultSet
Get an integer that is returned as a result of a query.
//package com.java2s; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { /**/*from w w w . ja va2s.com*/ * Get an integer that is returned as a result of a query. * @param conn * @param query * @return result * @throws SQLException */ public static int getIntFromDB(Connection conn, String query) throws SQLException { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(query); int ret = Integer.MIN_VALUE; if (rs.next()) { ret = rs.getInt(1); } rs.close(); st.close(); return ret; } }