Java Code Examples for java.sql.ResultSet#isLast()

The following examples show how to use java.sql.ResultSet#isLast() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcExecutor.java    From rheem with Apache License 2.0 6 votes vote down vote up
private void saveResult(FileChannel.Instance outputFileChannelInstance, ResultSet rs) throws IOException, SQLException {
    // Output results.
    final FileSystem outFs = FileSystems.getFileSystem(outputFileChannelInstance.getSinglePath()).get();
    try (final OutputStreamWriter writer = new OutputStreamWriter(outFs.create(outputFileChannelInstance.getSinglePath()))) {
        while (rs.next()) {
            //System.out.println(rs.getInt(1) + " " + rs.getString(2));
            ResultSetMetaData rsmd = rs.getMetaData();
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                writer.write(rs.getString(i));
                if (i < rsmd.getColumnCount()) {
                    writer.write('\t');
                }
            }
            if (!rs.isLast()) {
                writer.write('\n');
            }
        }
    } catch (UncheckedIOException e) {
        throw e.getCause();
    }
}
 
Example 2
Source File: SQLConnection.java    From act with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A handy function that closes a result set when an iterator has hit the end.  Does some ugly stuff with exceptions
 * but needs to be used inside an iterator.
 * @param results The result set to check for another row.
 * @param stmt A statement to close when we're out of results.
 * @return True if the result set has more rows, false otherwise (after closing).
 */
private static boolean hasNextHelper(ResultSet results, Statement stmt) {
  try {
    // TODO: is there a better way to do this?
    if (results.isLast()) {
      results.close(); // Tidy up if we find we're at the end.
      stmt.close();
      return false;
    } else {
      return true;
    }
  } catch (SQLException e) {
    /* Note: this is usually not a great thing to do.  In this circumstance we don't expect the
     * calling code to do anything but crash anyway, so... */
    throw new RuntimeException(e);
  }
}
 
Example 3
Source File: PaginationDataModel.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
public PaginationDataModel(Dialect aDialect, JTable aTable,
		ResultSet aResultSet) throws SQLException {
	owner = aTable;
	resultSet = aResultSet;
	metadata = aResultSet.getMetaData();
	dialect = aDialect;
	if (aResultSet.isLast()) {
		rowCount = 0;
	}
}
 
Example 4
Source File: Server.java    From HeavenMS with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void cleanNxcodeCoupons(Connection con) throws SQLException {
    if (!YamlConfig.config.server.USE_CLEAR_OUTDATED_COUPONS) return;
    
    long timeClear = System.currentTimeMillis() - 14 * 24 * 60 * 60 * 1000;
    
    PreparedStatement ps = con.prepareStatement("SELECT * FROM nxcode WHERE expiration <= ?");
    ps.setLong(1, timeClear);
    ResultSet rs = ps.executeQuery();

    if (!rs.isLast()) {
        PreparedStatement ps2 = con.prepareStatement("DELETE FROM nxcode_items WHERE codeid = ?");
        while (rs.next()) {
            ps2.setInt(1, rs.getInt("id"));
            ps2.addBatch();
        }
        ps2.executeBatch();
        ps2.close();
        
        ps2 = con.prepareStatement("DELETE FROM nxcode WHERE expiration <= ?");
        ps2.setLong(1, timeClear);
        ps2.executeUpdate();
        ps2.close();
    }
    
    rs.close();
    ps.close();
}
 
Example 5
Source File: UnsupportedOperationResultSetTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertIsLast() throws SQLException {
    for (ResultSet each : resultSets) {
        each.isLast();
    }
}
 
Example 6
Source File: UnsupportedOperationResultSetTest.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertIsLast() throws SQLException {
    for (ResultSet each : resultSets) {
        each.isLast();
    }
}
 
Example 7
Source File: OpenTestResource.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
/**
 * Gets all signal measurements from a test
 * @param testUID the test uid
 * @param testTime the begin of the test
 * @throws SQLException
 */
public SignalGraph(long testUID, long testTime, java.sql.Connection conn) throws SQLException {
	PreparedStatement psSignal = conn.prepareStatement("SELECT test_id, nt.name network_type, nt.group_name cat_technology, signal_strength, lte_rsrp, lte_rsrq, wifi_rssi, time "
       		+ "FROM signal "
       		+ "JOIN network_type nt "
       		+ "ON nt.uid = network_type_id "
       		+ "WHERE test_id = ? "
       		+ "ORDER BY time;");
       psSignal.setLong(1, testUID);
       
       ResultSet rsSignal = psSignal.executeQuery();
       
       boolean first = true;
       SignalGraphItem item = null;
       while (rsSignal.next()) {
       	long timeElapsed = rsSignal.getTimestamp("time").getTime() - testTime;
       	//there could be measurements taken before a test started
       	//in this case, only return the last one
       	if (first && timeElapsed > 0 && item != null) {
       		this.signalList.add(item);
       		first = false;
       	}
       	
       	//ignore measurements after a threshold of one minute
       	if (timeElapsed > MAX_TIME) 
       		break;
       	
       	
       	int signalStrength = rsSignal.getInt("signal_strength");
       	int lteRsrp = rsSignal.getInt("lte_rsrp");
       	int lteRsrq = rsSignal.getInt("lte_rsrq");
       	if (signalStrength == 0)
       		signalStrength = rsSignal.getInt("wifi_rssi");
       	
       	if (signalStrength > LOWER_BOUND)
       		item = new SignalGraphItem(Math.max(timeElapsed,0), rsSignal.getString("network_type"), signalStrength, lteRsrp, lteRsrq, rsSignal.getString("cat_technology"));
       	
       	
       	//put 5-let in the array if it is not the first one
       	if (!first || rsSignal.isLast()) {
       		if (timeElapsed < 0) {
       			item.timeElapsed = 1000;
       		}
       		this.signalList.add(item);
       	}
       }
       
       rsSignal.close();
       psSignal.close();
}
 
Example 8
Source File: OpenTestResource.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
/**
 * Gets all signal measurements from a test
 * @param testUID the test uid
 * @param testTime the begin of the test
 * @throws SQLException
 */
public SignalGraph(long testUID, long testTime, java.sql.Connection conn) throws SQLException {
	PreparedStatement psSignal = conn.prepareStatement("SELECT test_id, nt.name network_type, nt.group_name cat_technology, signal_strength, lte_rsrp, lte_rsrq, wifi_rssi, time "
       		+ "FROM signal "
       		+ "JOIN network_type nt "
       		+ "ON nt.uid = network_type_id "
       		+ "WHERE test_id = ? "
       		+ "ORDER BY time;");
       psSignal.setLong(1, testUID);
       
       ResultSet rsSignal = psSignal.executeQuery();
       
       boolean first = true;
       SignalGraphItem item = null;
       while (rsSignal.next()) {
       	long timeElapsed = rsSignal.getTimestamp("time").getTime() - testTime;
       	//there could be measurements taken before a test started
       	//in this case, only return the last one
       	if (first && timeElapsed > 0 && item != null) {
       		this.signalList.add(item);
       		first = false;
       	}
       	
       	//ignore measurements after a threshold of one minute
       	if (timeElapsed > MAX_TIME) 
       		break;
       	
       	
       	int signalStrength = rsSignal.getInt("signal_strength");
       	int lteRsrp = rsSignal.getInt("lte_rsrp");
       	int lteRsrq = rsSignal.getInt("lte_rsrq");
       	if (signalStrength == 0)
       		signalStrength = rsSignal.getInt("wifi_rssi");
       	
       	if (signalStrength > LOWER_BOUND)
       		item = new SignalGraphItem(Math.max(timeElapsed,0), rsSignal.getString("network_type"), signalStrength, lteRsrp, lteRsrq, rsSignal.getString("cat_technology"));
       	
       	
       	//put 5-let in the array if it is not the first one
       	if (!first || rsSignal.isLast()) {
       		if (timeElapsed < 0) {
       			item.timeElapsed = 1000;
       		}
       		this.signalList.add(item);
       	}
       }
       
       rsSignal.close();
       psSignal.close();
}
 
Example 9
Source File: OpenTestResource.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
/**
 * Gets all signal measurements from a test
 * @param testUID the test uid
 * @param testTime the begin of the test
 * @throws SQLException
 */
public SignalGraph(long testUID, long testTime, java.sql.Connection conn) throws SQLException {
	PreparedStatement psSignal = conn.prepareStatement("SELECT test_id, nt.name network_type, nt.group_name cat_technology, signal_strength, lte_rsrp, lte_rsrq, wifi_rssi, time "
       		+ "FROM signal "
       		+ "JOIN network_type nt "
       		+ "ON nt.uid = network_type_id "
       		+ "WHERE test_id = ? "
       		+ "ORDER BY time;");
       psSignal.setLong(1, testUID);
       
       ResultSet rsSignal = psSignal.executeQuery();
       
       boolean first = true;
       SignalGraphItem item = null;
       while (rsSignal.next()) {
       	long timeElapsed = rsSignal.getTimestamp("time").getTime() - testTime;
       	//there could be measurements taken before a test started
       	//in this case, only return the last one
       	if (first && timeElapsed > 0 && item != null) {
       		this.signalList.add(item);
       		first = false;
       	}
       	
       	//ignore measurements after a threshold of one minute
       	if (timeElapsed > MAX_TIME) 
       		break;
       	
       	
       	int signalStrength = rsSignal.getInt("signal_strength");
       	int lteRsrp = rsSignal.getInt("lte_rsrp");
       	int lteRsrq = rsSignal.getInt("lte_rsrq");
       	if (signalStrength == 0)
       		signalStrength = rsSignal.getInt("wifi_rssi");
       	
       	if (signalStrength > LOWER_BOUND)
       		item = new SignalGraphItem(Math.max(timeElapsed,0), rsSignal.getString("network_type"), signalStrength, lteRsrp, lteRsrq, rsSignal.getString("cat_technology"));
       	
       	
       	//put 5-let in the array if it is not the first one
       	if (!first || rsSignal.isLast()) {
       		if (timeElapsed < 0) {
       			item.timeElapsed = 1000;
       		}
       		this.signalList.add(item);
       	}
       }
       
       rsSignal.close();
       psSignal.close();
}