List of usage examples for java.sql ResultSet getLong
long getLong(String columnLabel) throws SQLException;
ResultSet
object as a long
in the Java programming language. From source file:edu.ucsd.library.xdre.web.StatsCollectionsReportController.java
public static long getDiskSize(String collectionId) throws SQLException { Connection con = null;/*from ww w . j ava 2 s .c o m*/ PreparedStatement ps = null; ResultSet rs = null; long size = 0; try { con = Constants.DAMS_DATA_SOURCE.getConnection(); ps = con.prepareStatement(StatsUsage.DLP_COLLECTION_RECORD_QUERY); ps.setString(1, collectionId); rs = ps.executeQuery(); if (rs.next()) { size = rs.getLong("SIZE_BYTES"); } } finally { Statistics.close(rs); Statistics.close(ps); Statistics.close(con); rs = null; ps = null; con = null; } return size; }
From source file:com.uber.hoodie.cli.utils.HiveUtil.java
private static long countRecords(String jdbcUrl, HoodieTableMetaClient source, String srcDb, String startDateStr, String endDateStr, String user, String pass) throws SQLException { Connection conn = HiveUtil.getConnection(jdbcUrl, user, pass); ResultSet rs = null; Statement stmt = conn.createStatement(); try {/*from ww w . j a v a 2 s .com*/ //stmt.execute("set mapred.job.queue.name=<queue_name>"); stmt.execute("set hive.input.format=org.apache.hadoop.hive.ql.io.HiveInputFormat"); stmt.execute("set hive.stats.autogather=false"); rs = stmt.executeQuery("select count(`_hoodie_commit_time`) as cnt from " + srcDb + "." + source.getTableConfig().getTableName() + " where datestr>'" + startDateStr + "' and datestr<='" + endDateStr + "'"); if (rs.next()) { return rs.getLong("cnt"); } return -1; } finally { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } } }
From source file:com.redhat.rhn.frontend.action.common.test.RhnSetActionTest.java
public static void verifyRhnSetData(Long uid, String setname, int size) throws HibernateException, SQLException { Session session = null;/*from w ww .j av a 2 s .co m*/ Connection c = null; Statement stmt = null; ResultSet rs = null; try { session = HibernateFactory.getSession(); session.flush(); c = session.connection(); stmt = c.createStatement(); String query = "select * from rhnset where user_id = " + uid.toString(); rs = stmt.executeQuery(query); assertNotNull(rs); int cnt = 0; while (rs.next()) { assertEquals(uid.longValue(), rs.getLong("USER_ID")); assertEquals(setname, rs.getString("LABEL")); cnt++; } assertEquals(size, cnt); } catch (SQLException e) { log.error("Error validating data.", e); throw e; } finally { HibernateHelper.cleanupDB(rs, stmt); } }
From source file:com.ubipass.middleware.ems.EMSUtil.java
/** * Get last time of system shutdown.//www .j av a 2s . c om * * @return time stamp of last system shutdown */ private static long getLastShutdownTime() { Connection conn = null; Statement stmt = null; ResultSet rs = null; long result = 0; try { conn = DBConnPool.getConnection(); // get last shutdown time from table sysconfig stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT currentTime FROM sysconfig"); rs.next(); result = rs.getLong(1); } catch (Exception e) { SystemLogger.error("[EMS] getLastShutdownTime() error: " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (Exception e) { } } return (result == 0) ? new Date().getTime() : result; }
From source file:com.tethrnet.manage.db.PublicKeyDB.java
/** * returns public key base on id/*from w ww . j av a 2s .c o m*/ * * @param con DB connection * @param publicKeyId key id * @return script object */ public static PublicKey getPublicKey(Connection con, Long publicKeyId) { PublicKey publicKey = null; try { PreparedStatement stmt = con.prepareStatement("select * from public_keys where id=?"); stmt.setLong(1, publicKeyId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString("key_nm")); publicKey.setPublicKey(rs.getString("public_key")); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id"))); publicKey.setType(rs.getString("type")); publicKey.setFingerprint(rs.getString("fingerprint")); publicKey.setCreateDt(rs.getTimestamp("create_dt")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return publicKey; }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * returns public key base on id/*from w w w . ja va2 s. co m*/ * * @param con DB connection * @param publicKeyId key id * @return script object */ public static PublicKey getPublicKey(Connection con, Long publicKeyId) { PublicKey publicKey = null; try { PreparedStatement stmt = con.prepareStatement("select * from public_keys where id=?"); stmt.setLong(1, publicKeyId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString(KEY_NM)); publicKey.setPublicKey(rs.getString(PUBLIC_KEY)); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong(PROFILE_ID))); publicKey.setType(rs.getString("type")); publicKey.setFingerprint(rs.getString("fingerprint")); publicKey.setCreateDt(rs.getTimestamp(CREATE_DT)); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return publicKey; }
From source file:com.tethrnet.manage.db.PublicKeyDB.java
/** * select all unique public keys for user * * @param userId user id/*from w w w . j a va 2s . c o m*/ * @return public key list for user */ public static List<PublicKey> getUniquePublicKeysForUser(Long userId) { Connection con = null; Map<String, PublicKey> keyMap = new LinkedHashMap(); try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from public_keys where user_id=? and enabled=true order by key_nm asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString("key_nm")); publicKey.setPublicKey(rs.getString("public_key")); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id"))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp("create_dt")); keyMap.put(publicKey.getKeyNm() + " (" + publicKey.getFingerprint() + ")", publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return new ArrayList(keyMap.values()); }
From source file:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static Collection<Mail> getMails(DBManager dbManager, long userId, boolean unreadOnly) { Collection<Mail> mailbox = new ArrayList<Mail>(); Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null; String sql = "SELECT `id`, `from`, `to`, `content`, `status`, `time_sent` " + "FROM rouge_mail WHERE `to` = ? "; if (unreadOnly) { sql += " AND `status` = 'unr'"; } else {/*from w w w . j a v a2 s . c om*/ sql += " AND NOT `status` = 'del'"; } try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setLong(1, userId); rs = stmt.executeQuery(); while (rs.next()) { mailbox.add(new Mail(rs.getLong("id"), rs.getLong("from"), rs.getLong("to"), new RougeObject(JSONObject.fromObject(rs.getString("content"))))); } return mailbox; } 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.PublicKeyDB.java
/** * select all unique public keys for user * * @param userId user id//from www . j ava 2 s. c o m * @return public key list for user */ public static List<PublicKey> getUniquePublicKeysForUser(Long userId) { Connection con = null; Map<String, PublicKey> keyMap = new LinkedHashMap(); try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from public_keys where user_id=? and enabled=true order by key_nm asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString(KEY_NM)); publicKey.setPublicKey(rs.getString(PUBLIC_KEY)); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong(PROFILE_ID))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp(CREATE_DT)); keyMap.put(publicKey.getKeyNm() + " (" + publicKey.getFingerprint() + ")", publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return new ArrayList(keyMap.values()); }
From source file:com.tethrnet.manage.db.PublicKeyDB.java
/** * returns public keys based on sort order defined * * @param sortedSet object that defines sort order * @param userId user id/* w ww. j a va2s . c o m*/ * @return sorted script list */ public static SortedSet getPublicKeySet(SortedSet sortedSet, Long userId) { ArrayList<PublicKey> publicKeysList = new ArrayList<PublicKey>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from public_keys where user_id = ? and enabled=true " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString("key_nm")); publicKey.setPublicKey(rs.getString("public_key")); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id"))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp("create_dt")); publicKeysList.add(publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(publicKeysList); return sortedSet; }