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:com.act.lcms.db.model.CuratedChemical.java
protected static List<CuratedChemical> fromResultSet(ResultSet resultSet) throws SQLException { List<CuratedChemical> results = new ArrayList<>(); while (resultSet.next()) { Integer id = resultSet.getInt(DB_FIELD.ID.getOffset()); String name = resultSet.getString(DB_FIELD.NAME.getOffset()); String inchi = resultSet.getString(DB_FIELD.INCHI.getOffset()); Double mass = resultSet.getDouble(DB_FIELD.MASS.getOffset()); Integer expectedCollisionVoltage = resultSet.getInt(DB_FIELD.EXPECTED_COLLISION_VOLTAGE.getOffset()); if (resultSet.wasNull()) { expectedCollisionVoltage = null; }//from w ww . ja va 2 s. c o m String referenceUrl = resultSet.getString(DB_FIELD.REFERENCE_URL.getOffset()); results.add(new CuratedChemical(id, name, inchi, mass, expectedCollisionVoltage, referenceUrl)); } return results; }
From source file:com.thoughtworks.go.server.database.DatabaseFixture.java
public static void assertColumnType(BasicDataSource dataSource, String tableName, String columnName, String expected) throws SQLException { Connection connection = dataSource.getConnection(); try {/* www . j ava 2 s . c o m*/ ResultSet set = connection.getMetaData().getColumns(null, null, null, null); while (set.next()) { if (set.getString("TABLE_NAME").equalsIgnoreCase(tableName) && set.getString("COLUMN_NAME").equalsIgnoreCase(columnName)) { String typeName = set.getString("TYPE_NAME"); int typeWidth = set.getInt("COLUMN_SIZE"); String type = typeName + "(" + typeWidth + ")"; assertThat("Expected " + columnName + " to be " + expected + " type but was " + type, type, is(expected)); return; } } Assert.fail("Column " + columnName + " does not exist"); } finally { try { connection.close(); } catch (Exception ignored) { } } }
From source file:ch.newscron.referral.ReferralManager.java
public static int numberOfRegisteredUsers(String shortURL) { Connection connection = null; PreparedStatement query = null; ResultSet rs = null; try {/*from w ww . j av a2s.co m*/ connection = connect(); query = connection.prepareStatement( "SELECT COUNT(*) as total FROM User, ShortURL WHERE User.campaignId = ShortURL.id AND ShortURL.shortUrl = ?"); query.setString(1, shortURL); rs = query.executeQuery(); rs.next(); int totalNumbUsers = rs.getInt("total"); return totalNumbUsers; } catch (Exception ex) { Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex); } finally { disconnect(connection, query, rs); } return -1; }
From source file:at.becast.youploader.database.SQLite.java
/** * Returns the DB Version for App Update purposes * /* w w w . java 2 s .c om*/ * @return An Integer with the current DB Version or 0 if there was a Error getting the Version * @throws SQLException */ public static int getVersion() throws SQLException { PreparedStatement prest = null; String sql = "PRAGMA `user_version`"; prest = c.prepareStatement(sql); ResultSet rs = prest.executeQuery(); if (rs.next()) { int version = rs.getInt(1); rs.close(); return version; } else { return 0; } }
From source file:module.entities.NameFinder.DB.java
public static TreeMap<Integer, String> getDemocracitCompletedConsultationBody() throws SQLException { TreeMap<Integer, String> cons_compl_desc = new TreeMap<>(); String sql = "SELECT id, completed_text " + "FROM consultation " + "WHERE completed = 1 AND id NOT IN (SELECT consultations_ner.id FROM consultations_ner);"; Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { int consID = rs.getInt("id"); String cons_compl_text = rs.getString("completed_text"); // String cons_compl = rs.getString("completed_text"); // if (cons_compl != null) { // String cons_text = cons_compl + "\n" + cons_desc; // cons_body.put(consID, cons_text); // } else { cons_compl_desc.put(consID, cons_compl_text); // } }/*from w w w . j av a2s. co m*/ return cons_compl_desc; }
From source file:module.entities.NameFinder.DB.java
public static TreeMap<Integer, String> getDemocracitConsultationBody() throws SQLException { TreeMap<Integer, String> cons_body = new TreeMap<>(); String sql = "SELECT id, short_description, completed_text " + "FROM consultation " + "WHERE id " // + "=3338;"; + "NOT IN (SELECT consultations_ner.id FROM consultations_ner);"; Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { int consID = rs.getInt("id"); String cons_desc = rs.getString("short_description"); // String cons_compl = rs.getString("completed_text"); // if (cons_compl != null) { // String cons_text = cons_compl + "\n" + cons_desc; // cons_body.put(consID, cons_text); // } else { cons_body.put(consID, cons_desc); // } }// w w w . j a va 2 s .com return cons_body; }
From source file:com.ultrapower.eoms.common.plugin.ecside.util.ECSideUtils.java
public static synchronized long getSEQSN(Connection conn, String SEQName) { long seqSN = 0; long startPoint = 1125983190000L; try {//from ww w . j ava 2 s. c o m String query = "select " + SEQName + ".nextval from dual"; Statement stmt = conn.createStatement(); ResultSet rest = stmt.executeQuery(query); if (rest.next()) { seqSN = rest.getInt(1); } } catch (Exception e) { long t1 = System.currentTimeMillis(); while (t1 == System.currentTimeMillis()) { // Thread.sleep(1); } seqSN = System.currentTimeMillis() - startPoint; } return seqSN; }
From source file:com.act.lcms.db.model.Plate.java
protected static List<Plate> platesFromResultSet(ResultSet resultSet) throws SQLException { List<Plate> results = new ArrayList<>(); while (resultSet.next()) { Integer id = resultSet.getInt(DB_FIELD.ID.getOffset()); String name = resultSet.getString(DB_FIELD.NAME.getOffset()); String description = resultSet.getString(DB_FIELD.DESCRIPTION.getOffset()); String barcode = resultSet.getString(DB_FIELD.BARCODE.getOffset()); String location = resultSet.getString(DB_FIELD.LOCATION.getOffset()); String plateType = resultSet.getString(DB_FIELD.PLATE_TYPE.getOffset()); String solvent = resultSet.getString(DB_FIELD.SOLVENT.getOffset()); Integer temperature = resultSet.getInt(DB_FIELD.TEMPERATURE.getOffset()); if (resultSet.wasNull()) { temperature = null;/* w ww .j a v a 2s. c om*/ } CONTENT_TYPE contentType = CONTENT_TYPE.valueOf(resultSet.getString(DB_FIELD.CONTENT_TYPE.getOffset())); results.add(new Plate(id, name, description, barcode, location, plateType, solvent, temperature, contentType)); } return results; }
From source file:com.googlecode.jtiger.modules.ecside.util.ECSideUtils.java
public static synchronized long getSEQSN(Connection conn, String SEQName) { long seqSN = 0; long startPoint = 1125983190000L; try {/*from w w w . j a va 2 s . c o m*/ String query = "select " + SEQName + ".nextval from dual"; Statement stmt = conn.createStatement(); ResultSet rest = stmt.executeQuery(query); if (rest.next()) { seqSN = rest.getInt(1); } } catch (Exception e) { long t1 = System.currentTimeMillis(); while (t1 == System.currentTimeMillis()) { // Thread.sleep(1); } seqSN = System.currentTimeMillis() - startPoint; } return seqSN; }
From source file:com.sql.SECExceptions.java
/** * Gets a count of errors where the description text matches. This is to * eliminate the repeat of entries from the application looping * * @param description String// w w w .ja va 2s .c o m * @return Integer count */ public static int getExistingException(String description) { int count = 0; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT COUNT(*) AS num FROM SECExceptions WHERE " + "timeOccurred >= CAST(CURRENT_TIMESTAMP AS DATE) AND exceptionDescrption LIKE ?"; ps = conn.prepareStatement(sql); ps.setString(1, description + "%"); rs = ps.executeQuery(); while (rs.next()) { count = rs.getInt("num"); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return count; }