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.adminpanel.JsonBuilder.java
public static JSONObject getAdminListJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;/*from w w w . java 2 s.co m*/ try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(jsFirstName, result.getString(dbFirstName)); jsonObject.put(jsLastName, result.getString(dbLastName)); jsonObject.put(jsMobileNumber, result.getString(dbMobileNumber)); jsonObject.put(jsEmail, result.getString(dbEmail)); jsonArray.put(jsonObject); } jsonObject = new JSONObject(); jsonObject.put(jsAdminList, jsonArray); jsonObject.put(jsDONE, 1); } catch (SQLException error) { Debug.debugLog("ADMIN RESULT SET: ", error); jsonObject = new JSONObject(); jsonObject.put(jsDONE, 0); } return jsonObject; }
From source file:com.bluepandora.therap.donatelife.adminpanel.JsonBuilder.java
public static JSONObject getFeedBackJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;/* ww w . j a v a2 s . c om*/ try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(jsIdUser, result.getString(dbIdUser)); jsonObject.put(jsReqTime, result.getString(dbReqTime)); jsonObject.put(jsSubject, result.getString(dbSubject)); jsonObject.put(jsComment, result.getString(dbComment)); jsonArray.put(jsonObject); } jsonObject = new JSONObject(); jsonObject.put(jsfeedBackList, jsonArray); jsonObject.put(jsDONE, 1); } catch (SQLException error) { Debug.debugLog("FEEDBACK RESULT SET: ", error); jsonObject = new JSONObject(); jsonObject.put(jsDONE, 0); } return jsonObject; }
From source file:las.DBConnector.java
public static ArrayList<Item> getItemTable() throws SQLException { ArrayList<Item> table = new ArrayList<>(); String data = "SELECT * FROM Items"; PreparedStatement pt = conn.prepareStatement(data); ResultSet rs = pt.executeQuery(); while (rs.next()) { table.add(new Item(rs.getString("title"), rs.getString("author"), rs.getString("type"), rs.getInt("Item_ID"), rs.getInt("amountleft"))); }// w ww.ja v a 2 s . co m return table; }
From source file:com.keybox.manage.db.ProfileDB.java
/** * returns profile based on id/* w w w. j a v a 2 s.c o m*/ * * @param con db connection object * @param profileId profile id * @return profile */ public static Profile getProfile(Connection con, Long profileId) { Profile profile = null; try { PreparedStatement stmt = con.prepareStatement("select * from profiles where id=?"); stmt.setLong(1, profileId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { profile = new Profile(); profile.setId(rs.getLong("id")); profile.setNm(rs.getString("nm")); profile.setDesc(rs.getString("desc")); profile.setHostSystemList(ProfileSystemsDB.getSystemsByProfile(con, profileId)); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return profile; }
From source file:edu.jhu.pha.vospace.oauth.MySQLOAuthProvider2.java
public static synchronized OAuthConsumer getConsumer(final String consumer_key) { return DbPoolServlet.goSql("Get oauth consumer", "select callback_url, consumer_key, consumer_secret, consumer_description, container from oauth_consumers where consumer_key = ?", new SqlWorker<Consumer>() { @Override//from www . j a v a 2 s . com public Consumer go(Connection conn, PreparedStatement stmt) throws SQLException { Consumer consumer = null; stmt.setString(1, consumer_key); ResultSet rs = stmt.executeQuery(); if (rs.next()) { consumer = new Consumer(rs.getString("consumer_key"), rs.getString("consumer_secret"), new MultivaluedMapImpl()); consumer.getAttributes().add("name", rs.getString("consumer_key")); consumer.getAttributes().add("description", rs.getString("consumer_description")); consumer.getAttributes().add("container", rs.getString("container")); } return consumer; } }); }
From source file:com.bluepandora.therap.donatelife.adminpanel.JsonBuilder.java
public static JSONObject getDonatorListJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject;//from w ww . ja v a2 s . c o m try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(jsMobileNumber, result.getString(dbMobileNumber)); jsonObject.put(jsFirstName, result.getString(dbFirstName)); jsonObject.put(jsLastName, result.getString(dbLastName)); jsonObject.put(jsGroupName, result.getString(dbGroupName)); jsonObject.put(jsDistName, result.getString(dbDistName)); jsonObject.put(jsGcmId, result.getString(dbGcmId)); jsonArray.put(jsonObject); } jsonObject = new JSONObject(); jsonObject.put(jsDonatorList, jsonArray); jsonObject.put(jsDONE, 1); } catch (SQLException error) { Debug.debugLog("DONATOR RESULT SET: ", error); jsonObject = new JSONObject(); jsonObject.put(jsDONE, 0); } return jsonObject; }
From source file:Main.java
private static void outputResultSet(ResultSet rs) throws Exception { ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); for (int i = 1; i < numberOfColumns + 1; i++) { String columnName = rsMetaData.getColumnName(i); System.out.print(columnName + " "); }/*from ww w . j av a 2s .co m*/ while (rs.next()) { for (int i = 1; i < numberOfColumns + 1; i++) { System.out.print(rs.getString(i) + " "); } System.out.println(); } }
From source file:com.keybox.manage.db.AuthDB.java
/** * get salt by user name/*ww w .j a v a2s. c o m*/ * * @param con DB connection * @param username username * @return salt */ private static String getSaltByUsername(Connection con, String username) { String salt = ""; try { PreparedStatement stmt = con .prepareStatement("select salt from users where enabled=true and username=?"); stmt.setString(1, username); ResultSet rs = stmt.executeQuery(); if (rs.next() && rs.getString("salt") != null) { salt = rs.getString("salt"); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return salt; }
From source file:com.keybox.manage.db.AuthDB.java
/** * get salt by authentication token// ww w .j a v a2 s .c o m * * @param con DB connection * @param authToken auth token * @return salt */ private static String getSaltByAuthToken(Connection con, String authToken) { String salt = ""; try { PreparedStatement stmt = con .prepareStatement("select salt from users where enabled=true and auth_token=?"); stmt.setString(1, authToken); ResultSet rs = stmt.executeQuery(); if (rs.next() && rs.getString("salt") != null) { salt = rs.getString("salt"); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return salt; }
From source file:edu.jhu.pha.vospace.oauth.MySQLOAuthProvider2.java
public static synchronized Token getRequestToken(final String tokenStr) { Token tokenObj = DbPoolServlet.goSql("Get oauth token", "select request_token, token_secret, consumer_key, callback_url, identity, container_name, accessor_write_permission " + "from oauth_accessors " + "join oauth_consumers on oauth_consumers.consumer_id = oauth_accessors.consumer_id " + "left outer join containers on containers.container_id = oauth_accessors.container_id " + "left outer join users on users.user_id = containers.user_id " + "left outer join user_identities on users.user_id = user_identities.user_id " + "where request_token = ? limit 1", new SqlWorker<Token>() { @Override//from w ww . ja v a2s . co m public Token go(Connection conn, PreparedStatement stmt) throws SQLException { Token token = null; stmt.setString(1, tokenStr); ResultSet rs = stmt.executeQuery(); if (rs.next()) { token = new Token(rs.getString("request_token"), rs.getString("token_secret"), rs.getString("consumer_key"), rs.getString("callback_url"), new MultivaluedMapImpl()); if (null != rs.getString("container_name")) token.getAttributes().add("root_container", rs.getString("container_name")); } return token; } }); return tokenObj; }