List of usage examples for java.sql ResultSet getFetchSize
int getFetchSize() throws SQLException;
ResultSet
object. From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/*from www. j av 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); // 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 showProperty(ResultSet rset) throws SQLException { switch (rset.getType()) { case ResultSet.TYPE_FORWARD_ONLY: System.out.println("Result set type: TYPE_FORWARD_ONLY"); break;/* w w w . j a v a 2s . c o m*/ case ResultSet.TYPE_SCROLL_INSENSITIVE: System.out.println("Result set type: TYPE_SCROLL_INSENSITIVE"); break; case ResultSet.TYPE_SCROLL_SENSITIVE: System.out.println("Result set type: TYPE_SCROLL_SENSITIVE"); break; default: System.out.println("Invalid type"); break; } switch (rset.getConcurrency()) { case ResultSet.CONCUR_UPDATABLE: System.out.println("Result set concurrency: ResultSet.CONCUR_UPDATABLE"); break; case ResultSet.CONCUR_READ_ONLY: System.out.println("Result set concurrency: ResultSet.CONCUR_READ_ONLY"); break; default: System.out.println("Invalid type"); break; } System.out.println("fetch size: " + rset.getFetchSize()); }
From source file:ar.com.zauber.commons.gis.spots.impl.SQLGeonameSpotDAO.java
/** @see ResultSetExtractor#extractData(java.sql.ResultSet) */ public final Object extractData(final ResultSet rset) throws SQLException, DataAccessException { final Collection<GeonameSpot> ret = new ArrayList<GeonameSpot>(rset.getFetchSize()); while (rset.next()) { try {/*from www . ja va2 s . c om*/ final Point point = (Point) reader.read(rset.getString("astext")); final GeonameSpot spot = new GeonameSpot(point, rset.getString("name"), rset.getString("ansiname"), rset.getString("countrycode"), rset.getLong("population")); spot.setId(rset.getLong("geonameid")); ret.add(spot); } catch (final ParseException e) { throw new RuntimeException(e); } } rset.close(); return ret; }
From source file:org.apache.sqoop.repository.derby.DerbyUpgradeGenericJdbcConnectorConfigAndInputNames.java
private Long getConfigId(boolean direction, String... args) { PreparedStatement statement = null; String configIdQuery = (direction) ? DerbySchemaUpgradeQuery.QUERY_SELECT_CONFIG_ID_BY_NAME_AND_DIRECTION : DerbySchemaUpgradeQuery.QUERY_SELECT_CONFIG_ID_BY_NAME; try {/*from ww w . ja v a 2s. c o m*/ statement = connection.prepareStatement(configIdQuery); for (int i = 0; i < args.length; ++i) { statement.setString(i + 1, args[i]); } ResultSet configIdResultSet = statement.executeQuery(); LOG.debug("QUERY(" + configIdQuery + ") with args [" + StringUtils.join(args, ",") + "] fetch size: " + configIdResultSet.getFetchSize()); if (!configIdResultSet.next() || configIdResultSet.getFetchSize() != 1) { return null; } return configIdResultSet.getLong(1); } catch (SQLException e) { throw new SqoopException(DerbyRepoError.DERBYREPO_0002, e); } finally { handler.closeStatements(statement); } }
From source file:org.castor.jpa.functional.AbstractSpringBaseTest.java
protected final void verifyPersistentBook(Book book) throws SQLException { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; int fetchSize = 0; long isbn = 0; String title = null;// w w w . ja v a2 s.c om try { // Load the book from the database. connection = this.dataSource.getConnection(); preparedStatement = connection.prepareStatement("SELECT isbn, title FROM book WHERE isbn = ?"); preparedStatement.setObject(1, Long.valueOf(book.getIsbn())); resultSet = preparedStatement.executeQuery(); fetchSize = resultSet.getFetchSize(); resultSet.next(); // Get values from result set. isbn = resultSet.getLong(1); title = resultSet.getString(2); } catch (SQLException e) { fail("Could not verify book instance: " + e.getMessage()); e.printStackTrace(); } finally { // Release resources. resultSet.close(); preparedStatement.close(); connection.close(); } // Verify result. assertEquals(1, fetchSize); assertEquals(book.getIsbn(), isbn); assertEquals(book.getTitle(), title); }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static Document addResultSetXmlPart(Element resultsElement, ResultSet rs, Document xmlDocumentResult) throws SQLException { // resultSet = statement.getResultSet(); // connection to an ACCESS MDB ResultSetMetaData rsmd = rs.getMetaData(); Element resultSetElement = xmlDocumentResult.createElement("ResultSet"); resultSetElement.setAttribute("fetchSize", String.valueOf(rs.getFetchSize())); resultsElement.appendChild(resultSetElement); int colCount = rsmd.getColumnCount(); while (rs.next()) { Element rowElement = xmlDocumentResult.createElement("Row"); rowElement.setAttribute("rowNumber", String.valueOf(rs.getRow())); resultsElement.appendChild(rowElement); for (int ii = 1; ii <= colCount; ii++) { String columnName = ""; if (!StringUtils.isBlank(rsmd.getTableName(ii))) { columnName += (rsmd.getTableName(ii)).toUpperCase() + "."; }/* w ww . j av a2 s. c om*/ columnName += (rsmd.getColumnName(ii)).toUpperCase(); String value = rs.getString(ii); Element node = xmlDocumentResult.createElement(createXmlName(columnName)); if (!StringUtils.isBlank(value)) { Text textNode = xmlDocumentResult.createTextNode(value.toString()); node.appendChild(textNode); } rowElement.appendChild(node); } resultSetElement.appendChild(rowElement); } return xmlDocumentResult; }
From source file:com.hygenics.parser.getDAOTemplate.java
private ResultSetExtractor<ArrayList<String>> getAllExtractor() { // create the array list of json strings for the query return (new ResultSetExtractor<ArrayList<String>>() { @Override/*from ww w . ja va2s . c o m*/ public ArrayList<String> extractData(ResultSet rs) throws SQLException, DataAccessException { ArrayList<String> results = new ArrayList<String>(rs.getFetchSize()); while (rs.next()) { JsonObject jobj = new JsonObject(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { jobj.add(rs.getMetaData().getColumnName(i), rs.getString(i)); } results.add(jobj.toString()); } return results; } }); }
From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java
public void testFetchSize() throws SQLException { stat = conn.createStatement();// w w w . j av a2 s . c om ResultSet rs = stat.executeQuery("SELECT * FROM SYSTEM_RANGE(1, 100)"); int a = stat.getFetchSize(); int b = rs.getFetchSize(); assertEquals(a, b); rs.setFetchSize(b + 1); b = rs.getFetchSize(); assertEquals(a + 1, b); }
From source file:com.hygenics.parser.getDAOTemplate.java
public ResultSetExtractor<ArrayList<String>> getJsonwithQuotesExtractor() { return (new ResultSetExtractor<ArrayList<String>>() { @Override// w w w. j ava2 s. c o m public ArrayList<String> extractData(ResultSet rs) throws SQLException, DataAccessException { // TODO Auto-generated method stub int j = 0; ArrayList<String> results = new ArrayList<String>(); JsonObject obj = null; int columns = 0; while (rs.next()) { if (columns == 0) { columns = rs.getMetaData().getColumnCount(); if (columns == 0) { return results; } } obj = null; obj = new JsonObject(); for (int i = 1; i <= columns; i++) { obj.add(rs.getMetaData().getColumnName(i), StringEscapeUtils.escapeJson(rs.getString(i).replaceAll("\t|\r|\n|\r\n|", ""))); } if (obj != null) { results.add(obj.toString()); } j++; } if (rs.getFetchSize() <= j) { rs.close(); } return results; } }); }
From source file:com.hygenics.parser.getDAOTemplate.java
/** * Returns a Json Based Extractor/*from ww w .j a v a2 s . com*/ * * @return */ public ResultSetExtractor<ArrayList<String>> getJsonExtractor() { return (new ResultSetExtractor<ArrayList<String>>() { @Override public ArrayList<String> extractData(ResultSet rs) throws SQLException, DataAccessException { // TODO Auto-generated method stub int j = 0; ArrayList<String> results = new ArrayList<String>(); JsonObject obj = null; int columns = 0; while (rs.next()) { if (columns == 0) { columns = rs.getMetaData().getColumnCount(); if (columns == 0) { return results; } } obj = null; obj = new JsonObject(); for (int i = 1; i <= columns; i++) { if (rs.getString(i) != null) { obj.add(rs.getMetaData().getColumnName(i), rs.getString(i).replaceAll("\t|\r|\n|\r\n|", "")); } else { obj.add(rs.getMetaData().getColumnName(i), ""); } } if (obj != null) { results.add(obj.toString()); } j++; } if (rs.getFetchSize() <= j) { rs.close(); } return results; } }); }