List of usage examples for java.sql ResultSet getInt
int getInt(String columnLabel) throws SQLException;
ResultSet
object as an int
in the Java programming language. From source file:agendavital.modelo.data.Noticia.java
/** * Funcion que devuelve las noticias en una fecha * * @param fecha La fecha en formato DD-MM-AAAA * @return/* w w w.j a v a 2 s . c o m*/ * @throws agendavital.modelo.excepciones.ConexionBDIncorrecta */ public static ArrayList<Noticia> Select(String fecha) throws ConexionBDIncorrecta { ResultSet rs = null; ArrayList<Noticia> noticias = null; try (Connection conexion = ConfigBD.conectar()) { noticias = new ArrayList<>(); String consulta = String.format("SELECT id_noticia from Noticias WHERE fecha = %s;", ConfigBD.String2Sql(fecha, false)); rs = conexion.createStatement().executeQuery(consulta); while (rs.next()) { noticias.add(new Noticia(rs.getInt("id_noticia"))); } return noticias; } catch (SQLException e) { throw new ConexionBDIncorrecta(); } }
From source file:com.adito.jdbc.JDBCSystemDatabase.java
/** * @param resultSet// www.j a v a 2 s .c o m * @return IpRestriction * @throws SQLException */ private static IpRestriction buildIpRestriction(ResultSet resultSet) throws SQLException { return new IpRestriction(resultSet.getInt("restriction_id"), resultSet.getString("address"), resultSet.getInt("type"), resultSet.getInt("priority")); }
From source file:com.wso2telco.dep.subscriptionvalidator.util.ValidatorDBUtils.java
public static List<ValidatorClassDTO> getValidatorClassForSMSSubscription() throws ValidatorException { Connection conn = null;//from w ww .java2 s .co m PreparedStatement ps = null; ResultSet results = null; String sql = "SELECT v.class as class,s.application_id as app,s.api_id as api FROM validator v, subscription_validator s WHERE v.id=s.validator_id"; List<ValidatorClassDTO> validatorClass = new ArrayList<ValidatorClassDTO>(); try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB); ps = conn.prepareStatement(sql); results = ps.executeQuery(); while (results.next()) { ValidatorClassDTO classDTO = new ValidatorClassDTO(); classDTO.setClassName(results.getString("class")); classDTO.setApp(results.getInt("app")); classDTO.setApi(results.getInt("api")); validatorClass.add(classDTO); } } catch (Exception e) { handleException("Error occured while getting Validator Class from the database", e); } finally { closeAllConnections(ps, conn, results); } return validatorClass; }
From source file:module.entities.NameFinder.DB.java
public static TreeMap<Integer, String> getDemocracitArticles(int consId) throws SQLException { TreeMap<Integer, String> all = new TreeMap<>(); String sql = "SELECT id, body " + "FROM articles " + "WHERE consultation_id = " + consId + " AND id NOT IN (SELECT enhancedentities.article_id FROM enhancedentities);"; Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(sql); // PreparedStatement preparedStatement = connection.prepareStatement(sql); // preparedStatement.setInt(1, consId); // System.out.println(sql); // ResultSet rs = preparedStatement.executeQuery(); Document doc;//from ww w.jav a2 s . c o m while (rs.next()) { int articleID = rs.getInt("id"); String article_text = rs.getString("body"); doc = Jsoup.parseBodyFragment(article_text); all.put(articleID, doc.text()); } return all; }
From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Gets the paths of a media.// w ww. j a v a 2 s .c om * @param con * @param media * @return * @throws SQLException */ public static Collection<String> getAlbumIdsOf(Connection con, Media media) throws SQLException { return select(con, "select N.NodeId from SC_Gallery_Path P, SB_Node_Node N where P.mediaId = ? and N.nodeId " + "= P.NodeId and P.instanceId = ? and N.instanceId = P.instanceId", Arrays.asList(media.getId(), media.getInstanceId()), new SelectResultRowProcessor<String>() { @Override protected String currentRow(final int rowIndex, final ResultSet rs) throws SQLException { return String.valueOf(rs.getInt(1)); } }); }
From source file:com.chaosinmotion.securechat.server.commands.Login.java
/** * Process the login request. This returns null if the user could not * be logged in./*from ww w. j a v a2 s. c o m*/ * * The expected parameters are 'username' and 'password', which should * be hashed. * * @param requestParams * @return * @throws IOException * @throws SQLException * @throws ClassNotFoundException */ public static UserInfo processRequest(JSONObject requestParams, String token) throws ClassNotFoundException, SQLException, IOException { String username = requestParams.optString("username"); String password = requestParams.optString("password"); /* * Obtain user information from database */ Connection c = null; PreparedStatement ps = null; ResultSet rs = null; try { c = Database.get(); ps = c.prepareStatement("SELECT userid, password " + "FROM Users " + "WHERE username = ?"); ps.setString(1, username); rs = ps.executeQuery(); if (rs.next()) { /* * If the result is found, hash the entry in the way it would * be hashed by the front end, and compare to see if the * hash codes match. (This requires that the hashed password * stored in the back-end has a consistent capitalization. * We arbitrarily pick lower-case for our SHA-256 hex string. */ int userID = rs.getInt(1); String spassword = rs.getString(2); /* * Encrypt password with token and salt */ spassword = spassword + Constants.SALT + token; spassword = Hash.sha256(spassword); /* * Compare; if matches, then return the user info record * so we can store away. While the SHA256 process returns * consistent case, we compare ignoring case anyway, just * because. :-) */ if (spassword.equalsIgnoreCase(password)) { return new UserInfo(userID); } } return null; } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } }
From source file:com.asakusafw.bulkloader.testutil.UnitTestUtil.java
/** * ?????/*w ww . j a v a 2s. co m*/ * @param tableName * @return */ public static boolean isExistTable(String tableName) throws Exception { String url = ConfigurationLoader.getProperty(Constants.PROP_KEY_DB_URL); String schema = url.substring(url.lastIndexOf("/") + 1, url.length()); String sql = "SELECT count(*) as count FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=? AND TABLE_SCHEMA=?"; Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { printLog("executeQuery???SQL" + sql + "" + tableName + "," + schema, "isExistTable"); conn = DBConnection.getConnection(); stmt = conn.prepareStatement(sql); stmt.setString(1, tableName); stmt.setString(2, schema); rs = stmt.executeQuery(); if (rs.next()) { int count = rs.getInt("count"); if (count > 0) { printLog("??????" + tableName, "isExistTable"); return true; } else { printLog("??????" + tableName, "isExistTable"); return false; } } else { printLog("??????" + tableName, "isExistTable"); return false; } } finally { DBConnection.closeRs(rs); DBConnection.closePs(stmt); DBConnection.closeConn(conn); } }
From source file:com.tethrnet.manage.db.SystemDB.java
/** * returns system by id/* w w w . java 2s . c o m*/ * * @param con DB connection * @param id system id * @return system */ public static HostSystem getSystem(Connection con, Long id) { HostSystem hostSystem = null; try { PreparedStatement stmt = con.prepareStatement("select * from system where id=?"); stmt.setLong(1, id); ResultSet rs = stmt.executeQuery(); while (rs.next()) { 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.setStatusCd(rs.getString("status_cd")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystem; }
From source file:com.clavain.alerts.Methods.java
public static void sendUPNotifications(ReturnServiceCheck sc) { Integer cid = sc.getCid();/*from ww w. j av a 2 s .c o m*/ try { Connection conn = connectToDatabase(com.clavain.muninmxcd.p); java.sql.Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery( "SELECT notifications.id as nid, contacts.* FROM `notifications` LEFT JOIN contacts ON notifications.contact_id = contacts.id WHERE check_id = " + cid); while (rs.next()) { Integer contact_id = rs.getInt("id"); String dayField = getScheduleFieldToCheck(); logger.info("[Check Notifications " + cid + "] Found " + rs.getString("contact_name")); if (rs.getString(dayField).equals("disabled")) { logger.info("[Check Notifications " + cid + "] " + rs.getString("contact_name") + " disabled notifications for today - skipping contact"); } else { String splitField = rs.getString(dayField); // figure out if this user got notifications enabled or disabled for the current hour and time String[] hours = splitField.split(";"); long a = getStampFromTimeAndZone(hours[0], rs.getString("timezone")); long b = getStampFromTimeAndZone(hours[1], rs.getString("timezone")); long cur = (System.currentTimeMillis() / 1000L); // if in range send notifications if (a < cur && b > cur) { String title = "Service OK: " + sc.getCheckname() + " (" + sc.getChecktype() + ")"; String message = "The Service is now up again."; String json = ""; if (rs.getInt("email_active") == 1) { logger.info("[Check Notifications " + cid + "] " + rs.getString("contact_name") + " Sending E-Mail"); sendMail(title, message, rs.getString("contact_email")); updateCheckNotificationLog(cid, contact_id, "UPTIME E-Mail send to " + rs.getString("contact_email"), "email"); } if (rs.getInt("sms_active") == 1) { logger.info("[Check Notifications " + cid + "] " + rs.getString("contact_name") + " Sending SMS"); sendSMS(title, message, rs.getString("contact_mobile_nr"), rs.getInt("user_id")); updateCheckNotificationLog(cid, contact_id, "UPTIME SMS send to " + rs.getString("contact_mobile_nr"), "sms"); } if (rs.getInt("pushover_active") == 1) { logger.info("[Check Notifications " + cid + "] " + rs.getString("contact_name") + " Sending Pushover Notification"); sendPushover(title, message, rs.getString("pushover_key")); updateCheckNotificationLog(cid, contact_id, "UPTIME PushOver Message send to " + rs.getString("pushover_key"), "pushover"); } } else { logger.info("[Check Notifications " + cid + "] " + rs.getString("contact_name") + " disabled notifications for this timerange - skipping contact"); } } } } catch (Exception ex) { logger.error("Error in sendUPNotifications for CID " + cid + " : " + ex.getLocalizedMessage()); } }
From source file:com.keybox.manage.db.SystemDB.java
/** * returns system by id//from w w w . jav a 2 s . c o m * * @param con DB connection * @param id system id * @return system */ public static HostSystem getSystem(Connection con, Long id) { HostSystem hostSystem = null; try { PreparedStatement stmt = con.prepareStatement("select * from system where id=?"); stmt.setLong(1, id); ResultSet rs = stmt.executeQuery(); while (rs.next()) { 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.setStatusCd(rs.getString(STATUS_CD)); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystem; }