List of usage examples for java.sql ResultSet next
boolean next() throws SQLException;
From source file:com.silverpeas.notation.model.RatingDAO.java
public static boolean existRaterRating(Connection con, RaterRatingPK pk) throws SQLException { PreparedStatement prepStmt = con.prepareStatement(QUERY_EXISTS_RATER_RATING); prepStmt.setString(1, pk.getInstanceId()); prepStmt.setString(2, pk.getContributionId()); prepStmt.setString(3, pk.getContributionType()); prepStmt.setString(4, pk.getRater().getId()); ResultSet rs = null; try {//from w ww.j a v a2 s . com rs = prepStmt.executeQuery(); return (rs.next()); } finally { DBUtil.close(rs, prepStmt); } }
From source file:dsd.dao.RawDataDAO.java
public static long GetMinTimestamp() { long timestamp = 0; try {/*from www . ja va 2 s .c o m*/ Connection con = DAOProvider.getDataSource().getConnection(); try { ResultSet results = DAOProvider.SelectTableSecure(tableName, " min(timestamp) ", "", "", con, null); while (results.next()) { timestamp = results.getTimestamp(1).getTime(); } } catch (Exception exc) { // exc.printStackTrace(); timestamp = 0; } con.close(); } catch (Exception exc) { exc.printStackTrace(); timestamp = 0; } return timestamp; }
From source file:com.pinterest.pinlater.backends.mysql.MySQLBackendUtils.java
/** * Gets the names of all queues found at the specified MySQL instance. Note that it is the * callers responsibility to close the connection after this method is called. * * @param conn Connection to the MySQL instance. * @param shardName//from w ww.ja v a 2s . c o m * @return Set containing queue name strings. */ public static Set<String> getQueueNames(Connection conn, String shardName) throws SQLException { ResultSet dbNameRs = conn.getMetaData().getCatalogs(); Set<String> queueNames = Sets.newHashSet(); while (dbNameRs.next()) { String name = dbNameRs.getString("TABLE_CAT"); if (name.startsWith(MySQLBackendUtils.PINLATER_QUEUE_DB_PREFIX) && shardNameFromDBName(name).equals(shardName)) { queueNames.add(MySQLBackendUtils.queueNameFromDBName(name)); } } return queueNames; }
From source file:com.sql.DocketNotification.java
/** * Gather a list of notifications for items that were docketed * //from www.ja v a2s.c om * @return */ public static List<DocketNotificationModel> getQueuedNotifications() { List<DocketNotificationModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM DocketNotifications"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { DocketNotificationModel item = new DocketNotificationModel(); item.setId(rs.getInt("id")); item.setSection(rs.getString("Section")); item.setSendTo(rs.getString("sendTo")); item.setMessageSubject(rs.getString("emailSubject")); item.setMessageBody(rs.getString("emailBody")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:dsd.dao.ParsedInputFilesDAO.java
public static boolean IsAlreadyParsed(String fileName) { boolean isAlreadyParsed = false; try {//from www. j ava 2 s.c om Connection con = DAOProvider.getDataSource().getConnection(); try { Object[] parameters = new Object[1]; parameters[0] = fileName; ResultSet results = DAOProvider.SelectTableSecure(tableName, " count(*) ", " name = ? ", "", con, parameters); while (results.next()) { isAlreadyParsed = results.getInt(1) == 1 ? true : false; } } catch (Exception exc) { exc.printStackTrace(); } con.close(); } catch (Exception exc) { exc.printStackTrace(); } return isAlreadyParsed; }
From source file:dsd.dao.ParsedInputFilesDAO.java
public static long GetCount(eFileType fileType) { long count = 0; try {/* www . j a va 2 s. c o m*/ Connection con = DAOProvider.getDataSource().getConnection(); try { Object[] parameters = new Object[1]; parameters[0] = new Integer(fileType.getCode()); ResultSet results = DAOProvider.SelectTableSecure(tableName, " count(*) ", " type = ? ", "", con, parameters); while (results.next()) { count = results.getLong(1); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); } catch (Exception exc) { exc.printStackTrace(); } return count; }
From source file:com.wavemaker.runtime.data.util.JDBCUtils.java
public static Object runSql(String sql[], String url, String username, String password, String driverClassName, Log logger, boolean isDDL) { Connection con = getConnection(url, username, password, driverClassName); try {/*w ww . j av a2 s . c om*/ try { con.setAutoCommit(true); } catch (SQLException ex) { throw new DataServiceRuntimeException(ex); } Statement s = con.createStatement(); try { try { for (String stmt : sql) { if (logger != null && logger.isInfoEnabled()) { logger.info("Running " + stmt); } s.execute(stmt); } if (!isDDL) { ResultSet r = s.getResultSet(); List<Object> rtn = new ArrayList<Object>(); while (r.next()) { // getting only the first col is pretty unuseful rtn.add(r.getObject(1)); } return rtn.toArray(new Object[rtn.size()]); } } catch (Exception ex) { if (logger != null && logger.isErrorEnabled()) { logger.error(ex.getMessage()); } throw ex; } } finally { try { s.close(); } catch (Exception ignore) { } } } catch (Exception ex) { if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } else { throw new DataServiceRuntimeException(ex); } } finally { try { con.close(); } catch (Exception ignore) { } } return null; }
From source file:com.silverpeas.notation.model.RatingDAO.java
private static void populateRatings(Connection con, Map<String, ContributionRating> ratings, String componentInstanceId, String contributionType, Collection<String> contributionIds) throws SQLException { PreparedStatement prepStmt = con.prepareStatement( QUERY_GET_RATINGS.replaceAll("@ids@", "'" + StringUtils.join(contributionIds, "','") + "'")); prepStmt.setString(1, componentInstanceId); prepStmt.setString(2, contributionType); ResultSet rs = null; try {/*from w w w.ja v a2 s . co m*/ rs = prepStmt.executeQuery(); while (rs.next()) { RatingRow current = resultSet2RatingRow(rs); ContributionRating contributionRating = ratings.get(current.getContributionId()); if (contributionRating == null) { contributionRating = new ContributionRating(new ContributionRatingPK( current.getContributionId(), componentInstanceId, contributionType)); ratings.put(contributionRating.getContributionId(), contributionRating); } contributionRating.addRaterRating(current.getRaterId(), current.getRating()); } } finally { DBUtil.close(rs, prepStmt); } }
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 + " "); }/* ww w. ja v a2 s.c o 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.l2jfree.sql.L2DatabaseInstaller.java
private static double getDatabaseRevision() { double revision = -1; Connection con = null;/* w w w.j a va 2 s . c om*/ try { con = L2Database.getConnection(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT revision FROM _revision ORDER BY revision DESC LIMIT 1"); if (rs.next()) revision = rs.getDouble(1); rs.close(); st.close(); } catch (SQLException e) { e.printStackTrace(); } finally { L2Database.close(con); } return revision; }