List of usage examples for java.sql ResultSet next
boolean next() throws SQLException;
From source file:com.nabla.dc.server.handler.fixed_asset.Asset.java
static public <P> boolean validateDepreciationPeriod(final Connection conn, final IAssetRecord asset, @Nullable final P pos, final IErrorList<P> errors) throws SQLException, DispatchException { final PreparedStatement stmt = StatementFormat.prepare(conn, "SELECT t.min_depreciation_period, t.max_depreciation_period" + " FROM fa_asset_category AS t INNER JOIN fa_company_asset_category AS r ON r.fa_asset_category_id=t.id" + " WHERE r.id=?;", asset.getCompanyAssetCategoryId()); try {/* w ww . ja va 2 s .c o m*/ final ResultSet rs = stmt.executeQuery(); try { if (!rs.next()) { errors.add(pos, asset.getCategoryField(), ServerErrors.UNDEFINED_ASSET_CATEGORY_FOR_COMPANY); return false; } if (rs.getInt("min_depreciation_period") > asset.getDepreciationPeriod() || rs.getInt("max_depreciation_period") < asset.getDepreciationPeriod()) { errors.add(pos, asset.getDepreciationPeriodField(), CommonServerErrors.INVALID_VALUE); return false; } } finally { rs.close(); } } finally { stmt.close(); } return true; }
From source file:net.big_oh.common.jdbc.JdbcProxyExerciser.java
private static void exerciseRegularSelect(Connection con) throws SQLException { logger.info(StringUtils.center("exercise regular select", 100, "-")); Statement stmt = null;//from w w w. j av a 2 s.c o m ResultSet rs = null; try { stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM TEST_TABLE"); while (rs.next()) { System.out.println(rs.getString("TEST_COLUMN")); } } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); } }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static List<Event> loadFrom(Connection connection, Instant time) throws SQLException, IOException { String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" " + "WHERE \"time\" >= ? ORDER BY \"time\" ASC, \"id\" ASC"; List<Event> events = new ArrayList<>(); try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setTimestamp(1, Timestamp.from(time)); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String evString = rs.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = rs.getLong("id"); event.removed = rs.getBoolean("removed"); events.add(event);//from w w w. j ava 2 s .c o m } } return events; }
From source file:com.oracle.tutorial.jdbc.CachedRowSetSample.java
public static void viewTable(Connection con) throws SQLException { Statement stmt = null;/*from ww w . j a v a 2 s . com*/ String query = "select * from MERCH_INVENTORY"; try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { System.out.println("Found item " + rs.getInt("ITEM_ID") + ": " + rs.getString("ITEM_NAME") + " (" + rs.getInt("QUAN") + ")"); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (stmt != null) { stmt.close(); } } }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static Optional<Event> loadUnique(Connection connection, Class<? extends Event> eventType) throws SQLException, IOException { String statement = "SELECT \"id\", \"data\" FROM \"events\" WHERE \"type\" = ? AND \"removed\" = false"; try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setString(1, eventType.getSimpleName()); ResultSet result = stmt.executeQuery(); if (result.next()) { String evString = result.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = result.getLong("id"); event.removed = false;/*from w ww . ja v a 2 s. c o m*/ return Optional.of(event); } else { return Optional.empty(); } } }
From source file:com.bluepandora.therap.donatelife.gcmservice.FindDonator.java
public static List findDonator(String groupId, String hospitalId, String mobileNumber, DatabaseService dbService) {//from w w w .ja va2 s .c om String query = GetQuery.getGcmIdOfDonatorQuery(groupId, hospitalId, mobileNumber); Debug.debugLog("FIND DONATOR: ", query); ResultSet result = dbService.getResultSet(query); List donatorList = new ArrayList<Donator>(); String gcmId = null; try { while (result.next()) { gcmId = result.getString("gcm_id"); mobileNumber = result.getString("mobile_number"); if (gcmId.length() > VALID_GCM_SIZE_GREATER) { donatorList.add(new Donator(mobileNumber, gcmId)); } } } catch (SQLException error) { Debug.debugLog("FINDING DONATOR SQL EXCEPTION!"); } return donatorList; }
From source file:com.concursive.connect.web.modules.upgrade.utils.UpgradeUtils.java
/** * Queries the database to see if the script has already been executed * * @param db Description of the Parameter * @param version Description of the Parameter * @return The installed value/*from www.j a v a 2s. c o m*/ * @throws java.sql.SQLException Description of the Exception */ public static boolean isInstalled(Connection db, String version) throws SQLException { boolean isInstalled = false; // Query the installed version PreparedStatement pst = db.prepareStatement( "SELECT script_version " + "FROM database_version " + "WHERE script_version = ? "); pst.setString(1, version); ResultSet rs = pst.executeQuery(); if (rs.next()) { isInstalled = true; } rs.close(); pst.close(); return isInstalled; }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static Optional<Event> load(Connection connection, long id) throws SQLException, IOException { try (PreparedStatement statement = connection .prepareStatement("SELECT \"data\",\"removed\" FROM \"events\" WHERE \"id\"=?")) { statement.setLong(1, id);/*w ww. j a v a 2s. c o m*/ ResultSet result = statement.executeQuery(); if (result.next()) { String evString = result.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = id; event.removed = result.getBoolean("removed"); return Optional.of(event); } else { return Optional.empty(); } } }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static List<Event> loadAfter(Connection connection, Instant time, long id) throws SQLException, IOException { String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" " + "WHERE \"time\" > ? OR (\"time\" = ? AND \"id\" > ?) ORDER BY \"time\" ASC, \"id\" ASC"; List<Event> events = new ArrayList<>(); try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setTimestamp(1, Timestamp.from(time)); stmt.setTimestamp(2, Timestamp.from(time)); stmt.setLong(3, id);//from w ww . j a v a 2s . c om LOG.debug("Executing query: {}", stmt); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String evString = rs.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = rs.getLong("id"); event.removed = rs.getBoolean("removed"); events.add(event); } } LOG.debug("Loaded {} events", events.size()); return events; }
From source file:cit360.sandbox.BackEndMenu.java
public final static void connect() { Connection conn = null;/*w ww. j a v a 2s.com*/ try { conn = DriverManager.getConnection("jdbc:mysql://localhost/cit361-sandbox?" + "user=root&password="); // Do something with the Connection } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } if (null != conn) { System.out.println("Connected to database!"); } else { System.out.println("Failed to make connection!"); } try { Statement stmt = conn.createStatement(); String query = "select * from movies ;"; //movies is the table name ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String name = rs.getObject(2).toString(); String Start_Time = rs.getObject(3).toString(); System.out.println(name + ": " + Start_Time); //movies table has name and price columns } } catch (SQLException e) { for (Throwable ex : e) { System.err.println("Error occurred " + ex); } System.out.println("Error in fetching data"); } }