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.keybox.manage.db.SessionAuditDB.java
/** * returns terminal logs for user session for host system * * @param sessionId session id/*from w ww . j a v a 2 s . c o m*/ * @param instanceId instance id for terminal session * @return session output for session */ public static List<SessionOutput> getTerminalLogsForSession(Connection con, Long sessionId, Integer instanceId) { List<SessionOutput> outputList = new LinkedList<>(); try { PreparedStatement stmt = con.prepareStatement( "select * from terminal_log where instance_id=? and session_id=? order by log_tm asc"); stmt.setLong(1, instanceId); stmt.setLong(2, sessionId); ResultSet rs = stmt.executeQuery(); StringBuilder outputBuilder = new StringBuilder(""); while (rs.next()) { outputBuilder.append(rs.getString("output")); } String output = outputBuilder.toString(); output = output.replaceAll("\\u0007|\u001B\\[K|\\]0;|\\[\\d\\d;\\d\\dm|\\[\\dm", ""); while (output.contains("\b")) { output = output.replaceFirst(".\b", ""); } DBUtils.closeRs(rs); SessionOutput sessionOutput = new SessionOutput(); sessionOutput.setSessionId(sessionId); sessionOutput.setInstanceId(instanceId); sessionOutput.getOutput().append(output); outputList.add(sessionOutput); DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return outputList; }
From source file:com.tethrnet.manage.db.UserDB.java
/** * returns all admin users based on sort order defined * @param sortedSet object that defines sort order * @return sorted user list//from w w w .j a v a2 s . c o m */ public static SortedSet getAdminUserSet(SortedSet sortedSet) { ArrayList<User> userList = new ArrayList<User>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from users where enabled=true and user_type like '" + User.ADMINISTRATOR + "' " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { User user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setAuthType(rs.getString("auth_type")); user.setUserType(rs.getString("user_type")); userList.add(user); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(userList); return sortedSet; }
From source file:io.mycat.server.packet.util.CharsetUtil.java
private static boolean getCharsetCollationFromMysql(DBHostConfig config) { String sql = "SELECT ID,CHARACTER_SET_NAME,COLLATION_NAME,IS_DEFAULT FROM INFORMATION_SCHEMA.COLLATIONS"; try (Connection conn = getConnection(config)) { if (conn == null) return false; try (Statement statement = conn.createStatement()) { ResultSet rs = statement.executeQuery(sql); while (rs != null && rs.next()) { int collationIndex = new Long(rs.getLong(1)).intValue(); String charsetName = rs.getString(2); String collationName = rs.getString(3); boolean isDefaultCollation = (rs.getString(4) != null && "Yes".equalsIgnoreCase(rs.getString(4))) ? true : false; INDEX_TO_CHARSET.put(collationIndex, charsetName); if (isDefaultCollation) { // ? charsetName collationIndexcollationIndex CHARSET_TO_INDEX.put(charsetName, collationIndex); }/* w ww . j a va 2 s . co m*/ CharsetCollation cc = new CharsetCollation(charsetName, collationIndex, collationName, isDefaultCollation); COLLATION_TO_CHARSETCOLLATION.put(collationName, cc); } if (COLLATION_TO_CHARSETCOLLATION.size() > 0) return true; return false; } catch (SQLException e) { logger.warn(e.getMessage()); } } catch (SQLException e) { logger.warn(e.getMessage()); } return false; }
From source file:com.keybox.manage.db.ProfileSystemsDB.java
/** * returns a list of systems for a given profile * * @param con DB connection//from w ww . jav a 2 s .co m * @param profileId profile id * @return list of host systems */ public static List<HostSystem> getSystemsByProfile(Connection con, Long profileId) { List<HostSystem> hostSystemList = new ArrayList<HostSystem>(); try { PreparedStatement stmt = con.prepareStatement( "select * from system s, system_map m where s.id=m.system_id and m.profile_id=? order by display_nm asc"); stmt.setLong(1, profileId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = new HostSystem(); hostSystem.setId(rs.getLong("id")); hostSystem.setDisplayNm(rs.getString("display_nm")); hostSystem.setUser(rs.getString("user")); hostSystem.setHost(rs.getString("host")); hostSystem.setPort(rs.getInt("port")); hostSystem.setAuthorizedKeys(rs.getString("authorized_keys")); hostSystem.setEnabled(rs.getBoolean("enabled")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { e.printStackTrace(); } return hostSystemList; }
From source file:com.app.dao.SearchQueryDAO.java
private static SearchQuery _createSearchQueryFromResultSet(ResultSet resultSet) throws SQLException { SearchQuery searchQuery = new SearchQuery(); searchQuery.setSearchQueryId(resultSet.getInt("searchQueryId")); searchQuery.setUserId(resultSet.getInt("userId")); searchQuery.setKeywords(resultSet.getString("keywords")); searchQuery.setCategoryId(resultSet.getString("categoryId")); searchQuery.setSubcategoryId(resultSet.getString("subcategoryId")); searchQuery.setSearchDescription(resultSet.getBoolean("searchDescription")); searchQuery.setFreeShippingOnly(resultSet.getBoolean("freeShippingOnly")); searchQuery.setNewCondition(resultSet.getBoolean("newCondition")); searchQuery.setUsedCondition(resultSet.getBoolean("usedCondition")); searchQuery.setUnspecifiedCondition(resultSet.getBoolean("unspecifiedCondition")); searchQuery.setAuctionListing(resultSet.getBoolean("auctionListing")); searchQuery.setFixedPriceListing(resultSet.getBoolean("fixedPriceListing")); searchQuery.setMaxPrice(resultSet.getDouble("maxPrice")); searchQuery.setMinPrice(resultSet.getDouble("minPrice")); searchQuery.setGlobalId(resultSet.getString("globalId")); searchQuery.setActive(resultSet.getBoolean("active")); return searchQuery; }
From source file:com.dynamobi.network.DynamoNetworkUdr.java
/** * Grabbing the list of repos along with their availability * status for internal use. /* ww w. j av a2 s . c o m*/ */ private static List<RepoInfo> getRepoUrls() throws SQLException { List<RepoInfo> repos = new ArrayList<RepoInfo>(); Connection conn = DriverManager.getConnection("jdbc:default:connection"); String query = "SELECT repo_url FROM localdb.sys_network.repositories " + "ORDER BY repo_url"; PreparedStatement ps = conn.prepareStatement(query); ps.execute(); ResultSet rs = ps.getResultSet(); while (rs.next()) { String repo = rs.getString(1); boolean accessible = true; try { JSONObject ob = downloadMetadata(repo); } catch (SQLException e) { if (e.getMessage().equals(URL_TIMEOUT)) accessible = false; } repos.add(new RepoInfo(repo, accessible)); } rs.close(); ps.close(); return repos; }
From source file:com.wso2telco.core.mnc.resolver.mncrange.McnRangeDbUtil.java
public static String getMncBrand(String mcc, String mnc) throws MobileNtException { Connection conn = null;/* www . jav a 2 s. co m*/ PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT operatorname " + "FROM operators " + "WHERE mcc = ? AND mnc = ?"; String mncBrand = null; try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB); ps = conn.prepareStatement(sql); ps.setString(1, mcc); ps.setString(2, mnc); rs = ps.executeQuery(); if (rs.next()) { mncBrand = rs.getString("operatorname"); } } catch (SQLException e) { handleException("Error occured while getting Brand for for mcc: and mnc: " + mcc + ":" + mnc + " from the database", e); } catch (Exception e) { handleException("Error occured while getting Brand for for mcc: and mnc: " + mcc + ":" + mnc + " from the database", e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } return mncBrand; }
From source file:com.keybox.manage.db.UserDB.java
/** * returns user base on id/*from www . j av a 2 s .com*/ * @param con DB connection * @param userId user id * @return user object */ public static User getUser(Connection con, Long userId) { User user = null; try { PreparedStatement stmt = con.prepareStatement("select * from users where id=?"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { user = new User(); user.setId(rs.getLong("id")); user.setFirstNm(rs.getString(FIRST_NM)); user.setLastNm(rs.getString(LAST_NM)); user.setEmail(rs.getString(EMAIL)); user.setUsername(rs.getString(USERNAME)); user.setPassword(rs.getString(PASSWORD)); user.setAuthType(rs.getString(AUTH_TYPE)); user.setUserType(rs.getString(USER_TYPE)); user.setSalt(rs.getString("salt")); user.setProfileList(UserProfileDB.getProfilesByUser(con, userId)); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:ca.qc.adinfo.rouge.leaderboard.db.LeaderboardDb.java
public static HashMap<String, Leaderboard> getLeaderboards(DBManager dbManager) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null; HashMap<String, Leaderboard> returnValue = new HashMap<String, Leaderboard>(); String sql = "SELECT `key` FROM rouge_leaderboards;"; try {//from ww w .java 2 s. com connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); rs = stmt.executeQuery(); while (rs.next()) { String key = rs.getString("key"); Leaderboard leaderboard = getLeaderboard(dbManager, key); if (leaderboard == null) { returnValue.put(key, new Leaderboard(key)); } else { returnValue.put(key, leaderboard); } } return returnValue; } catch (SQLException e) { log.error(stmt); log.error(e); return null; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:com.keybox.manage.db.UserDB.java
/** * returns users based on sort order defined * @param sortedSet object that defines sort order * @return sorted user list// w w w. j a v a2 s. com */ public static SortedSet getUserSet(SortedSet sortedSet) { ArrayList<User> userList = new ArrayList<>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from users where enabled=true " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { User user = new User(); user.setId(rs.getLong("id")); user.setFirstNm(rs.getString(FIRST_NM)); user.setLastNm(rs.getString(LAST_NM)); user.setEmail(rs.getString(EMAIL)); user.setUsername(rs.getString(USERNAME)); user.setPassword(rs.getString(PASSWORD)); user.setAuthType(rs.getString(AUTH_TYPE)); user.setUserType(rs.getString(USER_TYPE)); userList.add(user); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(userList); return sortedSet; }