Java Code Examples for java.sql.ResultSet.previous()

The following are Jave code examples for showing how to use previous() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GUI-Sorting-Time-Comparison-using-JavaFx   File: MainController.java   View Source Code Vote up 6 votes
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
	try {
		myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/gui_assignment?autoReconnect=true&useSSL=false", "root", "root");
		stmt = myConn.createStatement();
		
		ResultSet rs = stmt.executeQuery("select Temperature_Reading from temp_values");
		values = new int[rs.last() ? rs.getRow() : 0];
		
		int[] temp = {10000,100000,500000};
		noOfTempReadings = temp;
		
		rs.setFetchDirection(ResultSet.FETCH_REVERSE);
		rs.next();
		int i = values.length-1;
		while (rs.previous()) {
			values[i--] = rs.getInt("Temperature_Reading");
		}
	} catch (SQLException e) {
		e.printStackTrace();
		System.err.println("DATABASE CONNECT ERROR");
		System.exit(1);
	}
	
	System.out.println("No. of entries in database = "+values.length);
	
	ObservableList<String> pivotValues = FXCollections.observableArrayList("n/2","n/4","n/6");
	pivotSelect.setItems(pivotValues);
	pivotSelect.setValue("n/2");
	pivotSelect.setDisable(true);
	
	ObservableList<Integer> baseValues = FXCollections.observableArrayList(2,10,16);
	base.setItems(baseValues);
	base.setValue(10);
	base.setDisable(true);
	
	btnViewGraph.setDisable(true);
}
 
Example 2
Project: OpenDiabetes   File: TestViewAsterisks.java   View Source Code Vote up 6 votes
/**
 *  ensures that a given table has columns with a given name
 */
private void ensureTableColumns(String tableName,
                                String[] columnNames) throws SQLException {

    ResultSet res = m_connection.getMetaData().getColumns(null, null,
        tableName, "%");

    while (res.next()) {
        assertEquals(
            "unexpected column name in table \"" + tableName
            + "\" at position "
            + (res.getRow() - 1), res.getString(
                "COLUMN_NAME"), columnNames[res.getRow() - 1]);
    }

    res.previous();
    assertEquals("not enough columns in table \"" + tableName + "\"",
                 columnNames.length, res.getRow());
}
 
Example 3
Project: dev-courses   File: TestViewAsterisks.java   View Source Code Vote up 6 votes
/**
 *  ensures that a given table has columns with a given name
 */
private void ensureTableColumns(String tableName,
                                String[] columnNames) throws SQLException {

    ResultSet res = m_connection.getMetaData().getColumns(null, null,
        tableName, "%");

    while (res.next()) {
        assertEquals(
            "unexpected column name in table \"" + tableName
            + "\" at position "
            + (res.getRow() - 1), res.getString(
                "COLUMN_NAME"), columnNames[res.getRow() - 1]);
    }

    res.previous();
    assertEquals("not enough columns in table \"" + tableName + "\"",
                 columnNames.length, res.getRow());
}
 
Example 4
Project: parabuild-ci   File: TestViewAsterisks.java   View Source Code Vote up 6 votes
/**
 *  ensures that a given table has columns with a given name
 */
private void ensureTableColumns(String tableName,
                                String[] columnNames) throws SQLException {

    ResultSet res = m_connection.getMetaData().getColumns(null, null,
        tableName, "%");

    while (res.next()) {
        assertEquals(
            "unexpected column name in table \"" + tableName
            + "\" at position "
            + (res.getRow() - 1), res.getString(
                "COLUMN_NAME"), columnNames[res.getRow() - 1]);
    }

    res.previous();
    assertEquals("not enough columns in table \"" + tableName + "\"",
                 columnNames.length, res.getRow());
}
 
Example 5
Project: parabuild-ci   File: TestViewAsterisks.java   View Source Code Vote up 6 votes
/**
 *  ensures that a given table has columns with a given name
 */
private void ensureTableColumns(String tableName,
                                String[] columnNames) throws SQLException {

    ResultSet res = m_connection.getMetaData().getColumns(null, null,
        tableName, "%");

    while (res.next()) {
        assertEquals(
            "unexpected column name in table \"" + tableName
            + "\" at position "
            + (res.getRow() - 1), res.getString(
                "COLUMN_NAME"), columnNames[res.getRow() - 1]);
    }

    res.previous();
    assertEquals("not enough columns in table \"" + tableName + "\"",
                 columnNames.length, res.getRow());
}
 
Example 6
Project: parabuild-ci   File: TestViewAsterisks.java   View Source Code Vote up 6 votes
/**
 *  ensures that a given table has columns with a given name
 */
private void ensureTableColumns(String tableName,
                                String[] columnNames) throws SQLException {

    ResultSet res = m_connection.getMetaData().getColumns(null, null,
        tableName, "%");

    while (res.next()) {
        assertEquals(
            "unexpected column name in table \"" + tableName
            + "\" at position "
            + (res.getRow() - 1), res.getString(
                "COLUMN_NAME"), columnNames[res.getRow() - 1]);
    }

    res.previous();
    assertEquals("not enough columns in table \"" + tableName + "\"",
                 columnNames.length, res.getRow());
}
 
Example 7
Project: uroborosql   File: SecretColumnSqlFilterTest.java   View Source Code Vote up 5 votes
@Test
public void testSecretResultSet03() throws Exception {
	cleanInsert(Paths.get("src/test/resources/data/setup", "testExecuteQuery.ltsv"));

	try (SqlAgent agent = config.agent()) {
		SqlContext ctx = agent.contextFrom("example/select_product").param("product_id", new BigDecimal(0));
		ctx.setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);

		ResultSet result = agent.query(ctx);
		while (result.next()) {
			result.first();
			assertThat(result.isFirst(), is(true));
			result.previous();
			assertThat(result.isBeforeFirst(), is(true));
			result.next();
			assertThat(result.isBeforeFirst(), is(false));
			result.last();
			assertThat(result.isLast(), is(true));
			result.next();
			assertThat(result.isAfterLast(), is(true));
			result.previous();
			assertThat(result.isAfterLast(), is(false));
			result.beforeFirst();
			assertThat(result.isBeforeFirst(), is(true));
			result.afterLast();
			assertThat(result.isAfterLast(), is(true));
			result.next();

			assertThat(result.isWrapperFor(SecretResultSet.class), is(true));
			assertThat(result.unwrap(SecretResultSet.class).getCipher(), is(not(nullValue())));
			assertThat(result.unwrap(SecretResultSet.class).getCharset(), is(Charset.forName("UTF-8")));
			assertThat(result.unwrap(SecretResultSet.class).getCryptColumnNames(),
					is(Arrays.asList("PRODUCT_NAME")));
		}
		result.close();
	}
}