java.sql.ResultSet#isLast ( )源码实例Demo

下面列出了java.sql.ResultSet#isLast ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rheem   文件: JdbcExecutor.java
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();
    }
}
 
源代码2 项目: act   文件: SQLConnection.java
/**
 * 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);
  }
}
 
源代码3 项目: MogwaiERDesignerNG   文件: PaginationDataModel.java
public PaginationDataModel(Dialect aDialect, JTable aTable,
		ResultSet aResultSet) throws SQLException {
	owner = aTable;
	resultSet = aResultSet;
	metadata = aResultSet.getMetaData();
	dialect = aDialect;
	if (aResultSet.isLast()) {
		rowCount = 0;
	}
}
 
源代码4 项目: HeavenMS   文件: Server.java
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();
}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertIsLast() throws SQLException {
    for (ResultSet each : resultSets) {
        each.isLast();
    }
}
 
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertIsLast() throws SQLException {
    for (ResultSet each : resultSets) {
        each.isLast();
    }
}
 
源代码7 项目: open-rmbt   文件: OpenTestResource.java
/**
 * 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();
}
 
源代码8 项目: open-rmbt   文件: OpenTestResource.java
/**
 * 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();
}
 
源代码9 项目: open-rmbt   文件: OpenTestResource.java
/**
 * 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();
}