List of usage examples for java.sql ResultSet getString
String getString(String columnLabel) throws SQLException;
ResultSet
object as a String
in the Java programming language. From source file:com.bluepandora.therap.donatelife.jsonbuilder.DonatorMobileNumberJson.java
public static JSONObject getDonatorMobileNumberJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;//from w w w . j a v a 2 s. c om 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:moderation.Moderate.java
public static List getSavedList(String album_id) throws SQLException { List saved = new ArrayList(); String sql = "select post_id from albumpost where album_id=" + album_id + ";"; ResultSet rs = testing.Database.getResultset(sql, new setting.Conn().getConnection()); while (rs.next()) { saved.add(rs.getString("post_id")); }/*w w w. j av a 2s. co m*/ return saved; }
From source file:ch.newscron.registration.UserRegistration.java
private static List<User> parseResultSet(ResultSet resultSet) { List<User> userList = new ArrayList<>(); try {/*from w w w. j av a 2s.c om*/ while (resultSet.next()) { User newUser = new User(resultSet.getString("name"), resultSet.getString("lastName"), resultSet.getString("email"), resultSet.getLong("campaignId"), resultSet.getString("custID"), resultSet.getString("shortURL")); userList.add(newUser); } return userList; } catch (SQLException ex) { Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.thoughtworks.go.server.database.DatabaseFixture.java
public static void assertColumnType(BasicDataSource dataSource, String tableName, String columnName, String expected) throws SQLException { Connection connection = dataSource.getConnection(); try {/*w w w. ja v a2 s . co m*/ ResultSet set = connection.getMetaData().getColumns(null, null, null, null); while (set.next()) { if (set.getString("TABLE_NAME").equalsIgnoreCase(tableName) && set.getString("COLUMN_NAME").equalsIgnoreCase(columnName)) { String typeName = set.getString("TYPE_NAME"); int typeWidth = set.getInt("COLUMN_SIZE"); String type = typeName + "(" + typeWidth + ")"; assertThat("Expected " + columnName + " to be " + expected + " type but was " + type, type, is(expected)); return; } } Assert.fail("Column " + columnName + " does not exist"); } finally { try { connection.close(); } catch (Exception ignored) { } } }
From source file:com.bluepandora.therap.donatelife.jsonbuilder.BloodGroupJson.java
public static JSONObject getJsonBloodGroup(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;// ww w . j ava2s .co m try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(GROUP_ID, result.getString("group_id")); jsonObject.put(GROUP_NAME, result.getString("group_name")); jsonObject.put(GROUP_BNAME, result.getString("group_bname")); jsonArray.put(jsonObject); } jsonObject = new JSONObject(); jsonObject.put(BLOOD_GROUP, jsonArray); jsonObject.put(DONE, 1); } catch (SQLException error) { Debug.debugLog("BLOOD_GROUP RESULT SET: ", error); jsonObject = new JSONObject(); jsonObject.put(DONE, 0); } return jsonObject; }
From source file:com.bluepandora.therap.donatelife.jsonbuilder.UserProfileJson.java
public static JSONObject getUserProfileJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;//from www. ja va 2 s. c om try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(FIRST_NAME, result.getString("first_name")); jsonObject.put(LAST_NAME, result.getString("last_name")); jsonObject.put(GROUP_ID, result.getString("group_id")); jsonObject.put(DIST_ID, result.getString("dist_id")); jsonArray.put(jsonObject); } if (jsonArray.length() != 0) { jsonObject = new JSONObject(); jsonObject.put(PROFILE, jsonArray); jsonObject.put(DONE, 1); } else { jsonObject = new JSONObject(); jsonObject.put("message", Enum.MESSAGE_INVALID_USER); jsonObject.put(DONE, 0); } } catch (SQLException error) { Debug.debugLog("USER PROFILE RESULT DATA : ", error); jsonObject = new JSONObject(); jsonObject.put(DONE, 0); } return jsonObject; }
From source file:com.bluepandora.therap.donatelife.jsonbuilder.BloodRequestJson.java
public static JSONObject getBloodRequestJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;/* w w w . j a v a 2s . c om*/ try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(MOBILE_NUMBER, result.getString("mobile_number")); jsonObject.put(REQ_TIME, result.getString("req_time")); jsonObject.put(GROUP_ID, result.getString("group_id")); jsonObject.put(AMOUNT, result.getString("amount")); jsonObject.put(HOSP_ID, result.getString("hospital_id")); jsonObject.put(EMERGENCY, result.getString("emergency")); jsonArray.put(jsonObject); } jsonObject = new JSONObject(); jsonObject.put(BLOOD_REQUEST, jsonArray); jsonObject.put(DONE, 1); } catch (SQLException error) { Debug.debugLog("BLOOD_GROUP RESULT SET: ", error); jsonObject = new JSONObject(); jsonObject.put(DONE, 0); } return jsonObject; }
From source file:com.jagornet.dhcp.db.DbSchemaManager.java
/** * Validate schema.//from w w w .j ava2s .c om * * @param dataSource the data source * * @throws SQLException if there is a problem with the database * @throws IOExcpetion if there is a problem reading the schema file * * returns true if database was created, false otherwise */ public static boolean validateSchema(DataSource dataSource, String schemaFilename, int schemaVersion) throws SQLException, IOException { boolean schemaCreated = false; List<String> tableNames = new ArrayList<String>(); Connection conn = dataSource.getConnection(); DatabaseMetaData dbMetaData = conn.getMetaData(); log.info("JDBC Connection Info:\n" + "url = " + dbMetaData.getURL() + "\n" + "database = " + dbMetaData.getDatabaseProductName() + " " + dbMetaData.getDatabaseProductVersion() + "\n" + "driver = " + dbMetaData.getDriverName() + " " + dbMetaData.getDriverVersion()); String[] types = { "TABLE" }; ResultSet rs = dbMetaData.getTables(null, null, "%", types); if (rs.next()) { tableNames.add(rs.getString("TABLE_NAME")); } else { createSchema(dataSource, schemaFilename); dbMetaData = conn.getMetaData(); rs = dbMetaData.getTables(null, null, "%", types); schemaCreated = true; } while (rs.next()) { tableNames.add(rs.getString("TABLE_NAME")); } String[] schemaTableNames; if (schemaVersion <= 1) { schemaTableNames = TABLE_NAMES; } else { schemaTableNames = TABLE_NAMES_V2; } if (tableNames.size() == schemaTableNames.length) { for (int i = 0; i < schemaTableNames.length; i++) { if (!tableNames.contains(schemaTableNames[i])) { throw new IllegalStateException("Invalid database schema: unknown tables"); } } } else { throw new IllegalStateException("Invalid database schema: wrong number of tables"); } return schemaCreated; }
From source file:com.bluepandora.therap.donatelife.gcmservice.FindDonator.java
public static List findDonator(String groupId, String hospitalId, String mobileNumber, DatabaseService dbService) {//from ww w.j a v a2s . c om String query = GetQuery.getGcmIdOfDonatorQuery(groupId, hospitalId, mobileNumber); Debug.debugLog("FIND DONATOR: ", query); ResultSet result = dbService.getResultSet(query); List donatorList = new ArrayList<Donator>(); String gcmId = null; try { while (result.next()) { gcmId = result.getString("gcm_id"); mobileNumber = result.getString("mobile_number"); if (gcmId.length() > VALID_GCM_SIZE_GREATER) { donatorList.add(new Donator(mobileNumber, gcmId)); } } } catch (SQLException error) { Debug.debugLog("FINDING DONATOR SQL EXCEPTION!"); } return donatorList; }
From source file:com.bluepandora.therap.donatelife.service.CheckService.java
public static int requestTracker(String mobileNumber, String date, DatabaseService dbService) { String query = GetQuery.getPersonRequestTrackerQuery(mobileNumber, date); // Debug.debugLog("GET REQUEST: ", query); ResultSet result = dbService.getResultSet(query); int totalRequestFound = 0; String dailyRequest = "0"; try {//w w w . jav a 2 s .c o m while (result.next()) { dailyRequest = (String) result.getString("daily_request"); } totalRequestFound = Integer.parseInt(dailyRequest); } catch (SQLException error) { Logger.getLogger(CheckService.class.getName()).log(Level.SEVERE, null, error); } return totalRequestFound; }