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:edu.ku.brc.specify.conversion.ConvertMiscData.java
/** * @param oldDBConn//from w ww. j a v a 2 s. c o m * @param newDBConn * @param disciplineID * @return */ public static boolean convertKUInvertsObsData(final Connection oldDBConn, final Connection newDBConn) { Timestamp now = new Timestamp(System.currentTimeMillis()); IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); IdMapperIFace coMapper = IdMapperMgr.getInstance().addTableMapper("collectionobjectcatalog", "CollectionObjectCatalogID", false); PreparedStatement pStmt1 = null; PreparedStatement pStmt2 = null; PreparedStatement pStmt3 = null; try { pStmt1 = newDBConn.prepareStatement( "INSERT INTO collectionobjectattribute (Remarks, Text1, Number1, CollectionMemberID, TimestampCreated, TimestampModified, Version) VALUES(?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); pStmt2 = newDBConn.prepareStatement( "UPDATE collectionobjectattribute SET Remarks=?, Text1=?, Number1=? WHERE CollectionObjectAttributeID = ?"); pStmt3 = newDBConn.prepareStatement( "UPDATE collectionobject SET CollectionObjectAttributeID=? WHERE CollectionObjectID = ?"); int cnt = 0; String sql = " SELECT BiologicalObjectID, Remarks, Description, Count, TimestampCreated, TimestampModified FROM observation WHERE (Remarks IS NOT NULL) OR (Description IS NOT NULL) OR (Count IS NOT NULL)"; Statement stmt = oldDBConn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { int oldCOId = rs.getInt(1); Integer newCOId = coMapper.get(oldCOId); if (newCOId != null) { sql = "SELECT CollectionObjectAttributeID, CollectionMemberID FROM collectionobject WHERE CollectionObjectID = " + newCOId; Object[] row = BasicSQLUtils.getRow(sql); if (row == null || row.length == 0) { log.error("Couldn't get record for newCOId " + newCOId); continue; } Integer newCOAId = (Integer) row[0]; Integer collMemId = (Integer) row[1]; if (newCOAId != null) // Do Update { pStmt2.setString(1, rs.getString(2)); pStmt2.setString(2, rs.getString(3)); pStmt2.setInt(3, rs.getInt(4)); pStmt2.setInt(4, newCOAId); int rv = pStmt2.executeUpdate(); if (rv == 0) { System.err.println("Error updating newCOAId " + newCOAId); } } else // Do Insert { Timestamp ts = rs.getTimestamp(5); if (ts == null) { ts = now; } pStmt1.setString(1, rs.getString(2)); pStmt1.setString(2, rs.getString(3)); pStmt1.setInt(3, rs.getInt(4)); pStmt1.setInt(4, collMemId); pStmt1.setTimestamp(5, ts); pStmt1.setTimestamp(6, rs.getTimestamp(6)); pStmt1.setInt(7, 1); int rv = pStmt1.executeUpdate(); newCOAId = BasicSQLUtils.getInsertedId(pStmt1); if (rv == 0) { System.err.println("Error inserting newCOAId " + newCOAId); } } pStmt3.setInt(1, newCOAId); pStmt3.setInt(2, newCOId); int rv = pStmt3.executeUpdate(); if (rv == 0) { System.err.println("Error updating newCOId " + newCOId); } cnt++; } else { log.error("No mapped CO for Obs.BiologicalObjectID " + oldCOId); } } rs.close(); stmt.close(); System.out.println(String.format("Updated %d ColObj Records", cnt)); return true; } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (pStmt1 != null) pStmt1.close(); if (pStmt2 != null) pStmt2.close(); if (pStmt3 != null) pStmt3.close(); } catch (Exception ex) { } } return false; }
From source file:com.arcane.dao.Impl.UserDaoImpl.java
@Override public List<User> list() { //return all users LOG.info("Returning all the users"); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT * from user"; List<User> listUser = jdbcTemplate.query(sql, new RowMapper<User>() { @Override/*w w w . j a v a2 s. c o m*/ public User mapRow(ResultSet rs, int rowNumber) throws SQLException { User user = new User(); user.setUserid(rs.getInt("userid")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); return user; } }); return listUser; }
From source file:com.javacodegags.waterflooding.model.ResultImplemented.java
@Override public List<Result> getAll() { String sql = "SELECT * FROM results"; List<Result> listCaption = jdbcTemplate.query(sql, new RowMapper<Result>() { @Override// w w w . j a v a 2 s. co m public Result mapRow(ResultSet rs, int rowNum) throws SQLException { Result result = new Result(); result.setId(rs.getInt("id")); result.setMinimum(rs.getDouble("minimum")); result.setAverage(rs.getDouble("average")); return result; } }); return listCaption; }
From source file:com.javacodegags.waterflooding.model.ThermImplemented.java
@Override public List<Therm> getStackByCaptureId(int id) { String sql = "SELECT therm_set.id,therm_set.name " + "FROM intermediate " + "INNER JOIN caption " + "ON intermediate.foreign_to_caption=caption.Id " + "INNER JOIN criteria " + "ON intermediate.foreign_to_criteria=criteria.Id " + "INNER JOIN therm_set " + "ON criteria.foreign_to_therm=therm_set.id " + "Where intermediate.foreign_to_caption=" + id + ";"; List<Therm> listTherm = jdbcTemplate.query(sql, new RowMapper<Therm>() { @Override//from ww w . j a v a 2 s.c o m public Therm mapRow(ResultSet rs, int i) throws SQLException { Therm therm = new Therm(); therm.setId(rs.getInt("id")); therm.setName(rs.getString("name")); return therm; } }); return listTherm; }
From source file:wiki.result.ResultMapper.java
@Override public Result mapRow(ResultSet resultSet, int i) throws SQLException { long from = resultSet.getLong("fromPage"); long to = resultSet.getLong("toPage"); int indirection = resultSet.getInt("indirection"); int max = resultSet.getInt("max"); long time = resultSet.getLong("timeTaken"); return new Result(from, to, indirection, max, time); }
From source file:com.wabacus.system.datatype.IntType.java
public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException { return Integer.valueOf(rs.getInt(column)); }
From source file:database.UserMapper.java
@Override public User mapRow(ResultSet rs, int rowNum) throws SQLException { User user = new User(); Address address = new Address(); user.setId(rs.getInt("id")); user.setFirstname(rs.getString("firstname")); user.setLastname(rs.getString("lastname")); user.setEmail(rs.getString("email")); user.setNumber(rs.getString("number")); user.setBelt(rs.getString("belt")); address.setCity(rs.getString("city")); address.setStreetaddress(rs.getString("streetaddress")); address.setZipcode(rs.getString("zipcode")); user.setAddress(address);/*from w w w .j a va2s . com*/ return user; }
From source file:net.freechoice.model.orm.Map_Account.java
public FC_Account mapRow(final ResultSet rs, int rowNum) throws SQLException { FC_Account account = new FC_Account(); account.id = rs.getInt(1); account.id_user_ = rs.getInt(2);// ww w .j a va 2s. c o m account.date_create = rs.getDate(3); account.balance = rs.getBigDecimal(4); return account; }
From source file:com.persistent.cloudninja.mapper.RunningInstancesRowMapper.java
@Override public RunningInstanceEntity mapRow(ResultSet rs, int rowNum) throws SQLException { RunningInstanceEntity runningInstance = new RunningInstanceEntity(); runningInstance.setDay(rs.getInt("Day")); runningInstance.setMonth(rs.getInt("Month")); runningInstance.setYear(rs.getInt("Year")); runningInstance.setRoleName(rs.getString("RoleName")); runningInstance.setInstanceCountSum(rs.getInt("InstanceCountSum")); return runningInstance; }
From source file:dk.nsi.minlog.export.web.IsAlive.java
/** * Checks if we have access to the database by doing a simple query. * * @param out Writes out the result to this jsp writer. * @throws IOException//from w w w . j av a 2s . c o m * @throws SQLException */ public void checkAll(JspWriter out) throws Exception { Statement statement = null; Connection connection = null; try { // Checking database connection connection = dataSource.getConnection(); statement = connection.createStatement(); ResultSet rs = statement.executeQuery("SELECT 1"); if (!rs.next() || rs.getInt(1) != 1) { throw new RuntimeException("Invalid result from database"); } // Checking splunk connection (throws exception on error) try { splunkServiceFactory.getService().getInfo(); } catch (Exception ex) { throw new RuntimeException("Failed to connect to splunk"); } } finally { try { if (statement != null) statement.close(); } finally { if (connection != null) connection.close(); } } }