Java Code Examples for java.sql.PreparedStatement#setFetchDirection()

The following examples show how to use java.sql.PreparedStatement#setFetchDirection() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private PreparedStatement createFloatStatementForStateChecking(
    int[] parameterExpectedValues, int[] PreparedStatementExpectedValues,
    Connection conn, String sql) 
throws SQLException {
    PreparedStatement s = 
        internalCreateFloatStatementForStateChecking(conn, sql);
    s.setCursorName("StokeNewington");
    s.setFetchDirection(ResultSet.FETCH_REVERSE);
    s.setFetchSize(888);
    s.setMaxFieldSize(317);
    s.setMaxRows(91);

    // PreparedStatement Create        
    assertStatementState(
        parameterExpectedValues, PreparedStatementExpectedValues, s);
    return s;
}
 
Example 2
private PreparedStatement createFloatStatementForStateChecking(
    int[] parameterExpectedValues, int[] PreparedStatementExpectedValues,
    Connection conn, String sql) 
throws SQLException {
    PreparedStatement s = 
        internalCreateFloatStatementForStateChecking(conn, sql);
    s.setCursorName("StokeNewington");
    s.setFetchDirection(ResultSet.FETCH_REVERSE);
    s.setFetchSize(888);
    s.setMaxFieldSize(317);
    s.setMaxRows(91);

    // PreparedStatement Create        
    assertStatementState(
        parameterExpectedValues, PreparedStatementExpectedValues, s);
    return s;
}
 
Example 3
private PreparedStatement createFloatStatementForStateChecking(
        int[] parameterExpectedValues, int[] PreparedStatementExpectedValues,
        Connection conn, String sql)
        throws SQLException {
    PreparedStatement s =
            internalCreateFloatStatementForStateChecking(conn, sql);
    s.setCursorName("StokeNewington");
    s.setFetchDirection(ResultSet.FETCH_REVERSE);
    s.setFetchSize(888);
    s.setMaxFieldSize(317);
    s.setMaxRows(91);

    // PreparedStatement Create        
    assertStatementState(
            parameterExpectedValues, PreparedStatementExpectedValues, s);
    return s;
}
 
Example 4
public static List<Map> queryForList(Connection conn,String sql,int limit) throws SQLException {
	PreparedStatement ps = conn.prepareStatement(sql.trim());
	ps.setMaxRows(limit);
	ps.setFetchDirection(ResultSet.FETCH_FORWARD);
	ResultSet rs = ps.executeQuery();
	try {
		List result =  toListMap(limit, rs);
		return result;
	}finally {
		DBHelper.close(rs);
	}
}
 
Example 5
Source Project: hop   File: Database.java    License: Apache License 2.0 4 votes vote down vote up
public ResultSet openQuery( PreparedStatement ps, IRowMeta params, Object[] data )
  throws HopDatabaseException {
  ResultSet res;

  // Create a Statement
  try {
    log.snap( Metrics.METRIC_DATABASE_OPEN_QUERY_START, databaseMeta.getName() );

    log.snap( Metrics.METRIC_DATABASE_SQL_VALUES_START, databaseMeta.getName() );
    setValues( params, data, ps ); // set the parameters!
    log.snap( Metrics.METRIC_DATABASE_SQL_VALUES_STOP, databaseMeta.getName() );

    if ( canWeSetFetchSize( ps ) ) {
      int maxRows = ps.getMaxRows();
      int fs = Const.FETCH_SIZE <= maxRows ? maxRows : Const.FETCH_SIZE;
      // mysql have some restriction on fetch size assignment
      if ( databaseMeta.isMySqlVariant() ) {
        setMysqlFetchSize( ps, fs, maxRows );
      } else {
        // other databases seems not.
        ps.setFetchSize( fs );
      }

      ps.setFetchDirection( ResultSet.FETCH_FORWARD );
    }

    if ( rowlimit > 0 && databaseMeta.supportsSetMaxRows() ) {
      ps.setMaxRows( rowlimit );
    }

    log.snap( Metrics.METRIC_DATABASE_EXECUTE_SQL_START, databaseMeta.getName() );
    res = ps.executeQuery();
    log.snap( Metrics.METRIC_DATABASE_EXECUTE_SQL_STOP, databaseMeta.getName() );

    // MySQL Hack only. It seems too much for the cursor type of operation on
    // MySQL, to have another cursor opened
    // to get the length of a String field. So, on MySQL, we ignore the length
    // of Strings in result rows.
    //
    log.snap( Metrics.METRIC_DATABASE_GET_ROW_META_START, databaseMeta.getName() );
    rowMeta = getRowInfo( res.getMetaData(), databaseMeta.isMySqlVariant(), false );
    log.snap( Metrics.METRIC_DATABASE_GET_ROW_META_STOP, databaseMeta.getName() );
  } catch ( SQLException ex ) {
    throw new HopDatabaseException( "ERROR executing query", ex );
  } catch ( Exception e ) {
    throw new HopDatabaseException( "ERROR executing query", e );
  } finally {
    log.snap( Metrics.METRIC_DATABASE_OPEN_QUERY_STOP, databaseMeta.getName() );
  }

  return res;
}
 
Example 6
@Test
public void testPreparedStatementConfig() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("INSERT INTO test VALUES( ? , ?)", 1);
    preparedStatement.setInt(1, 1);
    preparedStatement.setString(2, "a");
    preparedStatement.getUpdateCount();
    preparedStatement.setFetchDirection(1);
    preparedStatement.getFetchDirection();
    preparedStatement.getResultSetConcurrency();
    preparedStatement.getResultSetType();
    preparedStatement.isClosed();
    preparedStatement.setPoolable(false);
    preparedStatement.isPoolable();
    preparedStatement.getWarnings();
    preparedStatement.clearWarnings();
    preparedStatement.setCursorName("test");
    preparedStatement.setMaxFieldSize(11);
    preparedStatement.getMaxFieldSize();
    preparedStatement.setMaxRows(10);
    preparedStatement.getMaxRows();
    preparedStatement.getParameterMetaData();
    preparedStatement.setEscapeProcessing(true);
    preparedStatement.setFetchSize(1);
    preparedStatement.getFetchSize();
    preparedStatement.setQueryTimeout(1);
    preparedStatement.getQueryTimeout();
    Connection connection = preparedStatement.getConnection();

    preparedStatement.execute();

    preparedStatement.getMoreResults();
    preparedStatement.getMoreResults(1);
    preparedStatement.getResultSetHoldability();
    preparedStatement.getMetaData();
    preparedStatement.getResultSet();

    preparedStatement.close();
    verify(mysqlPreparedStatement).getUpdateCount();
    verify(mysqlPreparedStatement).getMoreResults();
    verify(mysqlPreparedStatement).setFetchDirection(anyInt());
    verify(mysqlPreparedStatement).getFetchDirection();
    verify(mysqlPreparedStatement).getResultSetType();
    verify(mysqlPreparedStatement).isClosed();
    verify(mysqlPreparedStatement).setPoolable(anyBoolean());
    verify(mysqlPreparedStatement).getWarnings();
    verify(mysqlPreparedStatement).clearWarnings();
    verify(mysqlPreparedStatement).setCursorName(anyString());
    verify(mysqlPreparedStatement).setMaxFieldSize(anyInt());
    verify(mysqlPreparedStatement).getMaxFieldSize();
    verify(mysqlPreparedStatement).setMaxRows(anyInt());
    verify(mysqlPreparedStatement).getMaxRows();
    verify(mysqlPreparedStatement).setEscapeProcessing(anyBoolean());
    verify(mysqlPreparedStatement).getResultSetConcurrency();
    verify(mysqlPreparedStatement).getResultSetConcurrency();
    verify(mysqlPreparedStatement).getResultSetType();
    verify(mysqlPreparedStatement).getMetaData();
    verify(mysqlPreparedStatement).getParameterMetaData();
    verify(mysqlPreparedStatement).getMoreResults(anyInt());
    verify(mysqlPreparedStatement).setFetchSize(anyInt());
    verify(mysqlPreparedStatement).getFetchSize();
    verify(mysqlPreparedStatement).getQueryTimeout();
    verify(mysqlPreparedStatement).setQueryTimeout(anyInt());
    verify(mysqlPreparedStatement).getResultSet();
    assertThat(connection, CoreMatchers.<Connection>is(swConnection));
}
 
Example 7
Source Project: pentaho-kettle   File: Database.java    License: Apache License 2.0 4 votes vote down vote up
public ResultSet openQuery( PreparedStatement ps, RowMetaInterface params, Object[] data )
  throws KettleDatabaseException {
  ResultSet res;

  // Create a Statement
  try {
    log.snap( Metrics.METRIC_DATABASE_OPEN_QUERY_START, databaseMeta.getName() );

    log.snap( Metrics.METRIC_DATABASE_SQL_VALUES_START, databaseMeta.getName() );
    setValues( params, data, ps ); // set the parameters!
    log.snap( Metrics.METRIC_DATABASE_SQL_VALUES_STOP, databaseMeta.getName() );

    if ( canWeSetFetchSize( ps ) ) {
      int maxRows = ps.getMaxRows();
      int fs = Const.FETCH_SIZE <= maxRows ? maxRows : Const.FETCH_SIZE;
      // mysql have some restriction on fetch size assignment
      if ( databaseMeta.isMySQLVariant() ) {
        setMysqlFetchSize( ps, fs, maxRows );
      } else {
        // other databases seems not.
        ps.setFetchSize( fs );
      }

      ps.setFetchDirection( ResultSet.FETCH_FORWARD );
    }

    if ( rowlimit > 0 && databaseMeta.supportsSetMaxRows() ) {
      ps.setMaxRows( rowlimit );
    }

    log.snap( Metrics.METRIC_DATABASE_EXECUTE_SQL_START, databaseMeta.getName() );
    res = ps.executeQuery();
    log.snap( Metrics.METRIC_DATABASE_EXECUTE_SQL_STOP, databaseMeta.getName() );

    // MySQL Hack only. It seems too much for the cursor type of operation on
    // MySQL, to have another cursor opened
    // to get the length of a String field. So, on MySQL, we ignore the length
    // of Strings in result rows.
    //
    log.snap( Metrics.METRIC_DATABASE_GET_ROW_META_START, databaseMeta.getName() );
    rowMeta = getRowInfo( res.getMetaData(), databaseMeta.isMySQLVariant(), false );
    log.snap( Metrics.METRIC_DATABASE_GET_ROW_META_STOP, databaseMeta.getName() );
  } catch ( SQLException ex ) {
    throw new KettleDatabaseException( "ERROR executing query", ex );
  } catch ( Exception e ) {
    throw new KettleDatabaseException( "ERROR executing query", e );
  } finally {
    log.snap( Metrics.METRIC_DATABASE_OPEN_QUERY_STOP, databaseMeta.getName() );
  }

  return res;
}