List of usage examples for java.sql ResultSet next
boolean next() throws SQLException;
From source file:de.dakror.virtualhub.server.DBManager.java
public static Tags tags(File f, String catalog, Tags t) { try {/*from ww w .j a va 2s. co m*/ if (t == null) { ResultSet rs = connection.createStatement().executeQuery("SELECT TAGS FROM TAGS WHERE PATH = \"" + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\""); if (!rs.next()) return new Tags(); return new Tags(rs.getString(1).split(", ")); } else { if (t.getTags().length == 0) connection.createStatement().executeUpdate("DELETE FROM TAGS WHERE PATH = \"" + f.getPath().replace("\\", "/") + "\" AND CATALOG = \"" + catalog + "\""); else connection.createStatement() .executeUpdate("INSERT OR REPLACE INTO TAGS VALUES(\"" + f.getPath().replace("\\", "/") + "\", \"" + catalog + "\", \"" + t.serialize() + "\")"); } } catch (SQLException e1) { e1.printStackTrace(); } return null; }
From source file:com.sql.EmailOut.java
/** * Gathers current emails waiting to be sent out. * * @return List (EmailOutModel)/*from ww w .j a v a 2s . com*/ */ public static List<EmailOutModel> getEmailOutQueue() { List<EmailOutModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM EmailOut WHERE okToSend = 1"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { EmailOutModel item = new EmailOutModel(); item.setId(rs.getInt("id")); item.setSection(rs.getString("Section")); item.setCaseYear(rs.getString("caseYear")); item.setCaseType(rs.getString("caseType")); item.setCaseMonth(rs.getString("caseMonth")); item.setCaseNumber(rs.getString("caseNumber")); item.setTo(rs.getString("to")); item.setFrom(rs.getString("from")); item.setCc(rs.getString("cc")); item.setBcc(rs.getString("bcc")); item.setSubject(rs.getString("subject")); item.setBody(rs.getString("body")); item.setUserID(rs.getInt("UserID")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:com.tfm.utad.sqoopdata.SqoopVerticaDB.java
private static Long findMaxID(Connection conn) { Long id = (long) 0; Statement stmt = null;/* w ww . ja va2 s .co m*/ String query; try { stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); query = "SELECT MAX(id) AS id FROM s1.coordinates"; LOG.info("Query execution: " + query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { id = (long) rs.getInt("id"); } } catch (SQLException e) { LOG.error("SQLException error: " + e.toString()); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException ex) { LOG.error("Statement error: " + ex.toString()); } } if (conn != null) { try { conn.close(); } catch (SQLException ex) { LOG.error("Connection error: " + ex.toString()); } } } return id; }
From source file:com.linkedin.databus.bootstrap.utils.BootstrapDBCleanerMain.java
private static List<String> getSourceNames(Connection conn) throws SQLException { List<String> srcNames = new ArrayList<String>(); String sql = "select src from bootstrap_sources"; ResultSet rs = null; PreparedStatement stmt = null; try {//from ww w.j a v a 2 s .c om stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); while (rs.next()) { String name = rs.getString(1); srcNames.add(name); } } finally { DBHelper.close(rs, stmt, null); } return srcNames; }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * returns all key placement statuses//from w ww. j a va 2 s . c o m * * @param con DB connection object * @param userId user id */ private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) { List<HostSystem> hostSystemList = new ArrayList<HostSystem>(); try { PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystemList; }
From source file:com.bluepandora.therap.donatelife.adminpanel.JsonBuilder.java
public static JSONObject getHospitalListJson(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = null;/* w w w.j a va 2s . c o m*/ try { while (result.next()) { jsonObject = new JSONObject(); jsonObject.put(jsHospitalId, result.getString(dbHospitalId)); jsonObject.put(jsDistName, result.getString(dbDistName)); jsonObject.put(jsHospitalName, result.getString(dbHospitalName)); jsonObject.put(jsHospitalBName, result.getString(dbHospitalBName)); jsonArray.put(jsonObject); } if (jsonArray.length() != 0) { jsonObject = new JSONObject(); jsonObject.put("hospitalList", jsonArray); jsonObject.put(jsDONE, 1); } else { jsonObject = new JSONObject(); jsonObject.put("message", "NO HOSPITAL LIST FOUND!"); jsonObject.put(jsDONE, 0); } } catch (SQLException error) { Debug.debugLog("Hospital List: ", error); jsonObject = new JSONObject(); jsonObject.put(jsDONE, 0); } return jsonObject; }
From source file:com.bluepandora.therap.donatelife.adminpanel.JsonBuilder.java
public static JSONObject adminProfile(ResultSet result) throws JSONException { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = null;/*from w w w . ja v a 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(jsEmail, result.getString(dbEmail)); jsonObject.put(jsMobileNumber, result.getString(dbMobileNumber)); jsonArray.put(jsonObject); } if (jsonArray.length() != 0) { jsonObject = new JSONObject(); jsonObject.put("admin", jsonArray); jsonObject.put(jsDONE, 1); } else { jsonObject = new JSONObject(); jsonObject.put("message", "NO VALID ADMIN FOUND!"); jsonObject.put(jsDONE, 0); } } catch (SQLException error) { Debug.debugLog("Admin SQL : ", error); jsonObject = new JSONObject(); jsonObject.put(jsDONE, 0); } return jsonObject; }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * returns the first system that authorized keys has not been tried * * @param userId user id/*from w w w . ja va 2 s . com*/ * @return hostSystem systems for authorized_keys replacement */ public static HostSystem getNextPendingSystem(Long userId) { HostSystem hostSystem = null; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from status where (status_cd like ? or status_cd like ? or status_cd like ?) and user_id=? order by id asc"); stmt.setString(1, HostSystem.INITIAL_STATUS); stmt.setString(2, HostSystem.AUTH_FAIL_STATUS); stmt.setString(3, HostSystem.PUBLIC_KEY_FAIL_STATUS); stmt.setLong(4, userId); ResultSet rs = stmt.executeQuery(); if (rs.next()) { hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return hostSystem; }
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * returns all key placement statuses/*from ww w . j av a2s .co m*/ * * @param con DB connection object * @param userId user id */ private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) { List<HostSystem> hostSystemList = new ArrayList<>(); try { PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString(STATUS_CD)); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystemList; }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * returns key placement status of system * * @param systemId system id//from w w w . java 2 s . co m * @param userId user id */ public static HostSystem getSystemStatus(Long systemId, Long userId) { Connection con = null; HostSystem hostSystem = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("select * from status where id=? and user_id=?"); stmt.setLong(1, systemId); stmt.setLong(2, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return hostSystem; }