List of usage examples for java.sql Statement setFetchSize
void setFetchSize(int rows) throws SQLException;
ResultSet
objects generated by this Statement
. From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false);/*from w ww. j av a 2s . co m*/ Statement st = conn.createStatement(); st.setFetchSize(1); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st.executeUpdate("insert into survey (id,name ) values (2,'nameValue')"); st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); rs.setFetchSize(1); outputResultSet(rs); checkForWarning(rs.getWarnings()); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/*from w ww . j a v a 2s. com*/ String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); Statement stmt = connection.createStatement(); int fetchSize = stmt.getFetchSize(); // Set the fetch size on the statement stmt.setFetchSize(100); ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); // Change the fetch size on the result set resultSet.setFetchSize(100); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/*from ww w . j a v a2 s. c o m*/ String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); // Get the fetch size of a statement Statement stmt = connection.createStatement(); int fetchSize = stmt.getFetchSize(); // Set the fetch size on the statement stmt.setFetchSize(100); ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); // Change the fetch size on the result set resultSet.setFetchSize(100); }
From source file:Main.java
public static void main(String[] args) throws SQLException { // DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@yourDB", "scott", "tiger"); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); stmt.setFetchSize(1); ResultSet rset = stmt.executeQuery("select EMPNO, ENAME, SAL from EMP"); showProperty(rset);/* w ww . j a v a 2 s . co m*/ while (rset.next()) { System.out.println(rset.getInt(1) + " " + rset.getString(2) + " " + rset.getInt(3)); } doSomeChanges(conn); // Place the cursor before the first row rset.beforeFirst(); while (rset.next()) { System.out.println(rset.getInt(1) + " " + rset.getString(2) + " " + rset.getInt(3)); } rset.close(); stmt.close(); cleanup(conn); conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/*from w w w . jav a 2s.c o m*/ String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); // Get the fetch size of a statement Statement stmt = connection.createStatement(); int fetchSize = stmt.getFetchSize(); // Set the fetch size on the statement stmt.setFetchSize(100); // Create a result set ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); // Change the fetch size on the result set System.out.println(resultSet.getFetchSize()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);// w w w. j av a 2s . c om String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); // Get the fetch size of a statement Statement stmt = connection.createStatement(); int fetchSize = stmt.getFetchSize(); // Set the fetch size on the statement stmt.setFetchSize(100); // Create a result set ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); // Change the fetch size on the result set resultSet.setFetchSize(100); }
From source file:com.dattack.dbcopy.engine.DbCopyTask.java
private Statement createStatement(Connection connection) throws SQLException { Statement stmt = connection.createStatement(); if (dbcopyJobBean.getSelectBean().getFetchSize() > 0) { stmt.setFetchSize(dbcopyJobBean.getSelectBean().getFetchSize()); }/*from w ww . ja v a 2 s. com*/ return stmt; }
From source file:edu.ku.brc.specify.toycode.mexconabio.AgentNames.java
/** * /*w w w .j a v a 2 s . c om*/ */ public void process() { //String sql = "SELECT collector_name FROM raw WHERE collector_name IS NOT NULL AND collector_name LIKE '%;%' limit 4000,1000"; String sql = "SELECT collector_name FROM raw WHERE collector_name IS NOT NULL limit 4000,1000"; try { Statement stmt = oldDBConn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { String str = rs.getString(1); System.out.println("\n" + str); parseForNames(str); } rs.close(); stmt.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.zimbra.cs.db.MySQL.java
@Override public void enableStreaming(Statement stmt) throws SQLException { if (LC.jdbc_results_streaming_enabled.booleanValue()) { stmt.setFetchSize(Integer.MIN_VALUE); }//from w ww .j a va 2 s . co m }
From source file:com.taobao.datax.plugins.reader.postgrereader.PostgreReader.java
@Override public int startRead(LineSender lineSender) { DBResultSetSender proxy = DBResultSetSender.newSender(lineSender); proxy.setMonitor(getMonitor());/* w ww. ja v a 2 s .c o m*/ proxy.setDateFormatMap(genDateFormatMap()); String sql = param.getValue(ParamKey.sql); logger.info(String.format("PostgreReader start to query %s .", sql)); ResultSet rs = null; Connection connection = null; try { connection = getCon(); connection.setAutoCommit(false); Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); logger.info("set postgre statement fetch size"); stmt.setFetchSize(fetchSize); logger.info("connection info autoCommit:" + connection.getAutoCommit() + " fetchSize" + stmt.getFetchSize()); rs = DBUtils.query(stmt, sql); logger.info("get a ResultSet"); proxy.sendToWriter(rs); logger.info("send to writer"); proxy.flush(); getMonitor().setStatus(PluginStatus.READ_OVER); return PluginStatus.SUCCESS.value(); } catch (SQLException e) { logger.error(ExceptionTracker.trace(e)); throw new DataExchangeException(e); } finally { if (null != rs) { DBUtils.closeResultSet(rs); } if (connection != null) { try { connection.close(); } catch (Exception ignore) { } } } }