List of usage examples for java.sql ResultSet next
boolean next() throws SQLException;
From source file:com.bluepandora.therap.donatelife.jsonbuilder.DonatorMobileNumberJson.java
public static JSONObject getDonatorMobileNumberJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;// w ww .j av a 2 s. c o m try { while (result.next()) { jsonObject = new JSONObject(); String mobileNumber = result.getString("mobile_number"); jsonObject.put("mobileNumber", mobileNumber); jsonArray.put(jsonObject); } if (jsonArray.length() != 0) { jsonObject = new JSONObject(); jsonObject.put("number", jsonArray); jsonObject.put("done", 1); } else { jsonObject = new JSONObject(); jsonObject.put("message", Enum.MESSAGE_NO_SUITABLE_DONATOR_FOUND); jsonObject.put("done", 0); } } catch (SQLException error) { Debug.debugLog("FINDING DONATOR MOBILE NUMBER EXCPTION OCCURS!"); jsonObject = new JSONObject(); jsonObject.put("done", 0); } return jsonObject; }
From source file:com.thoughtworks.go.server.datamigration.M001.java
static boolean required(Connection cxn) throws SQLException { try (Statement s = cxn.createStatement()) { final ResultSet rs = s .executeQuery("SELECT COUNT(*) as remaining FROM pipelineselections WHERE version = 0"); rs.next(); return rs.getInt("remaining") > 0; }/*w ww . ja v a 2s. co m*/ }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the int value in the first row and column of the result set, and close * the statement./*from w w w . j a va 2 s .c om*/ * * @param stmt * must already have parameters set * @return {@link Integer#MIN_VALUE} if the result set is empty */ public static int firstInt(PreparedStatement stmt) throws SQLException { ResultSet rs = stmt.executeQuery(); int i = rs.next() ? rs.getInt(1) : Integer.MIN_VALUE; stmt.close(); return i; }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the long value in the first row and column of the result set, and * close the statement./* www . j ava 2 s .c o m*/ * * @param stmt * must already have parameters set * @return {@link Long#MIN_VALUE} if the result set is empty */ public static long firstLong(PreparedStatement stmt) throws SQLException { ResultSet rs = stmt.executeQuery(); long l = rs.next() ? rs.getLong(1) : Long.MIN_VALUE; stmt.close(); return l; }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the long values in the first row of the result set, and close the * statement.// w w w . jav a 2s . c o m * * @param stmt * must already have parameters set * @return null if the result set is empty * @since 1.4.0 */ public static long[] firstLongRow(PreparedStatement stmt) throws SQLException { long[] l = null; ResultSet rs = stmt.executeQuery(); if (rs.next()) { l = new long[rs.getMetaData().getColumnCount()]; for (int i = 0; i < l.length; i++) { l[i] = rs.getLong(i + 1); } } stmt.close(); return l; }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the String values in the first column of the result set, and close the * statement./*from w w w .j a v a2s. c o m*/ * * @param stmt * must already have parameters set * @return null if the result set is empty * @since 1.5.0 */ public static List<String> allStrings(PreparedStatement stmt) throws SQLException { List<String> s = null; ResultSet rs = stmt.executeQuery(); if (rs.next()) { s = new ArrayList<String>(); do { s.add(rs.getString(1)); } while (rs.next()); } stmt.close(); return s; }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the long values in the first column of the result set, and close the * statement.//from w w w .java 2 s . c o m * * @param stmt * must already have parameters set * @return null if the result set is empty * @since 1.4.0 */ public static long[] allLongs(PreparedStatement stmt) throws SQLException { long[] l = null; ResultSet rs = stmt.executeQuery(); if (rs.next()) { LongList list = new ArrayLongList(); do { list.add(rs.getLong(1)); } while (rs.next()); l = list.toArray(); } stmt.close(); return l; }
From source file:com.bluepandora.therap.donatelife.jsonbuilder.DonationRecordJson.java
public static JSONObject getDonationRecordJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;// w ww. ja va2 s . c o m try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(DONATION_DATE, result.getString("donation_date")); jsonObject.put(DONATION_RECORD, result.getString("donation_detail")); jsonArray.put(jsonObject); } if (jsonArray.length() != 0) { jsonObject = new JSONObject(); jsonObject.put(DONATION_RECORD, jsonArray); jsonObject.put(DONE, 1); } else { jsonObject = new JSONObject(); jsonObject.put("message", Enum.MESSAGE_DONATION_NOT_FOUND); jsonObject.put(DONE, 0); } } catch (SQLException error) { Debug.debugLog("BLOOD_GROUP RESULT SET: ", error); jsonObject = new JSONObject(); jsonObject.put(DONE, 0); } return jsonObject; }
From source file:de.dakror.virtualhub.server.DBManager.java
public static JSONObject tagdata(String catalog) { JSONObject o = new JSONObject(); try {/* ww w .j a v a 2 s .c o m*/ ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM TAGS"); while (rs.next()) { o.put(rs.getString(1), rs.getString(3).split(", ")); } } catch (Exception e) { e.printStackTrace(); } return o; }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the insert statement, get the first generated key as a long, and close the statement. * //from w ww . ja v a 2 s.co m * @param stmt * must have been created with {@link Statement#RETURN_GENERATED_KEYS} and already * have parameters set * @return 0 if the statement did not generate any keys */ public static long firstLongKey(PreparedStatement stmt) throws SQLException { stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); long l = rs.next() ? rs.getLong(1) : 0L; stmt.close(); return l; }