List of usage examples for java.sql ResultSet getType
int getType() throws SQLException;
ResultSet
object. From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); 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,null)"); st = conn.createStatement();/* www . j a v a 2s. c om*/ ResultSet rs = st.executeQuery("SELECT * FROM survey"); int rsType = rs.getType(); if (rsType == java.sql.ResultSet.TYPE_FORWARD_ONLY) { System.out.println("java.sql.ResultSet.TYPE_FORWARD_ONLY"); } else if (rsType == java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE) { System.out.println("java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE"); } else if (rsType == java.sql.ResultSet.TYPE_SCROLL_SENSITIVE) { System.out.println("java.sql.ResultSet.TYPE_SCROLL_SENSITIVE"); } else { // it is an error } rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { try {/* w w w. j a va 2s .co m*/ String url = "jdbc:odbc:yourdatabasename"; String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String user = "guest"; String password = "guest"; Class.forName(driver); Connection connection = DriverManager.getConnection(url, user, password); Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery("SELECT * from DUMMY"); System.out.println(rs.getType()); System.out.println(rs.getConcurrency()); rs.deleteRow(); rs.close(); rs.close(); stmt.close(); connection.close(); } catch (Exception e) { System.err.println(e); } }
From source file:TypeConcurrency.java
public static void main(String args[]) { String url = "jdbc:mySubprotocol:myDataSource"; Connection con;//w ww.j ava 2 s. c o m Statement stmt; try { Class.forName("myDriver.ClassName"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "myLogin", "myPassword"); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet srs = stmt.executeQuery("SELECT * FROM COFFEES"); int type = srs.getType(); System.out.println("srs is type " + type); int concur = srs.getConcurrency(); System.out.println("srs has concurrency " + concur); while (srs.next()) { String name = srs.getString("COF_NAME"); int id = srs.getInt("SUP_ID"); float price = srs.getFloat("PRICE"); int sales = srs.getInt("SALES"); int total = srs.getInt("TOTAL"); System.out.print(name + " " + id + " " + price); System.out.println(" " + sales + " " + total); } srs.close(); stmt.close(); con.close(); } catch (SQLException ex) { System.err.println("-----SQLException-----"); System.err.println("SQLState: " + ex.getSQLState()); System.err.println("Message: " + ex.getMessage()); System.err.println("Vendor: " + ex.getErrorCode()); } }
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;//from www .j a va2s .c om 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:com.netspective.sparx.sql.QueryResultSetDataSource.java
protected void setResultSet(ResultSet resultSet) { this.resultSet = queryResultSet.getResultSet(); try {/*www.jav a 2 s .c om*/ if (cacheColumnData) { final ResultSetMetaData metaData = resultSet.getMetaData(); retrievedColumnData = new boolean[metaData.getColumnCount()]; cachedColumnData = new Object[metaData.getColumnCount()]; } scrollable = resultSet.getType() != ResultSet.TYPE_FORWARD_ONLY ? true : false; } catch (SQLException e) { log.error("Unable to set result set", e); throw new NestableRuntimeException(e); } activeRowIndex = -1; calculatedTotalRows = false; }
From source file:BQJDBC.QueryResultTest.Timeouttest.java
@Test public void QueryResultTest05() { final String sql = "SELECT word FROM publicdata:samples.shakespeare WHERE word=\"huzzah\""; final String description = "The word \"huzzah\" NOTE: It doesn't appear in any any book, so it returns with a null #WHERE"; this.logger.info("Test number: 05"); this.logger.info("Running query:" + sql); java.sql.ResultSet Result = null; try {/* w w w.j a va 2s .c o m*/ Result = Timeouttest.con.createStatement().executeQuery(sql); this.logger.debug(Result.getMetaData().getColumnCount()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(Result); this.logger.debug(description); try { if (Result.getType() != ResultSet.TYPE_FORWARD_ONLY) Assert.assertFalse(Result.first()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail(e.toString()); } }
From source file:BQJDBC.QueryResultTest.QueryResultTest.java
@Test public void QueryResultTest05() { final String sql = "SELECT word FROM publicdata:samples.shakespeare WHERE word='huzzah' ;"; final String description = "The word \"huzzah\" NOTE: It doesn't appear in any any book, so it returns with a null #WHERE"; this.logger.info("Test number: 05"); this.logger.info("Running query:" + sql); java.sql.ResultSet Result = null; try {/*from w ww. ja v a 2 s .co m*/ Result = QueryResultTest.con.createStatement().executeQuery(sql); this.logger.debug(Result.getMetaData().getColumnCount()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(Result); this.logger.debug(description); try { if (Result.getType() != ResultSet.TYPE_FORWARD_ONLY) Assert.assertFalse(Result.first()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail(e.toString()); } }
From source file:de.innovationgate.webgate.api.jdbc.custom.JDBCSource.java
private void startResultSet(ResultSet resultSet) throws SQLException { if (resultSet.getType() != ResultSet.TYPE_FORWARD_ONLY && !resultSet.isBeforeFirst()) { resultSet.beforeFirst();// ww w . j a va 2 s. c o m } }
From source file:com.toxind.benchmark.thrid.ibatis.sqlmap.engine.execution.SqlExecutor.java
private void handleResults(StatementScope statementScope, ResultSet rs, int skipResults, int maxResults, RowHandlerCallback callback) throws SQLException { try {// w w w .j a v a 2 s . c o m statementScope.setResultSet(rs); ResultMap resultMap = statementScope.getResultMap(); if (resultMap != null) { // Skip Results if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) { if (skipResults > 0) { rs.absolute(skipResults); } } else { for (int i = 0; i < skipResults; i++) { if (!rs.next()) { return; } } } // Get Results int resultsFetched = 0; while ((maxResults == SqlExecutor.NO_MAXIMUM_RESULTS || resultsFetched < maxResults) && rs.next()) { Object[] columnValues = resultMap.resolveSubMap(statementScope, rs).getResults(statementScope, rs); callback.handleResultObject(statementScope, columnValues, rs); resultsFetched++; } } } finally { statementScope.setResultSet(null); } }
From source file:com.glaf.core.jdbc.QueryHelper.java
protected void skipRows(ResultSet rs, int start) throws SQLException { if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) { if (start != 0) { logger.debug("rs absolute " + start); rs.absolute(start);/*w w w.ja v a 2 s. co m*/ } } else { for (int i = 0; i < start; i++) { rs.next(); } } }