List of usage examples for java.sql ResultSet CONCUR_READ_ONLY
int CONCUR_READ_ONLY
To view the source code for java.sql ResultSet CONCUR_READ_ONLY.
Click Source Link
ResultSet
object that may NOT be updated. From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/testdb", "root", ""); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = statement.executeQuery("SELECT * FROM products"); // Move to the second row resultSet.absolute(2);/*from w ww.j a va 2s . c o m*/ System.out.println("You are now in: " + resultSet.getRow()); // Move 2 records forward from the current position (fourth row) resultSet.relative(2); System.out.println("You are now in: " + resultSet.getRow()); // Move to the last row in the result set resultSet.absolute(-1); System.out.println("You are now in: " + resultSet.getRow()); // Move 3 records backward from the current position (second row) resultSet.relative(-3); System.out.println("You are now in: " + resultSet.getRow()); connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/testdb", "root", ""); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = statement.executeQuery("SELECT * FROM products"); while (resultSet.next()) { String productCode = resultSet.getString("product_code"); String productName = resultSet.getString("product_name"); int quantity = resultSet.getInt("quantity"); double price = resultSet.getDouble("price"); System.out.println(productCode + "\t" + productName + "\t" + quantity + "\t" + price); }// w w w . j a v a 2s . c o m while (resultSet.previous()) { String productCode = resultSet.getString("product_code"); String productName = resultSet.getString("product_name"); int quantity = resultSet.getInt("quantity"); double price = resultSet.getDouble("price"); System.out.println(productCode + "\t" + productName + "\t" + quantity + "\t" + price); } connection.close(); }
From source file:ScrollableRs.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL"; Connection conn = DriverManager.getConnection(jdbcUrl, "yourName", "mypwd"); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery("SELECT ssn, name, salary FROM EMPLOYEES"); while (rs.next()) { printRow(rs);/*from ww w . j a v a 2 s. c o m*/ } rs.afterLast(); System.out.println("\"After-last-row\" = " + rs.isAfterLast()); rs.beforeFirst(); System.out.println("\"Before-first-row\" = " + rs.isBeforeFirst()); rs.first(); printRow(rs); rs.last(); printRow(rs); rs.previous(); printRow(rs); rs.next(); printRow(rs); rs.absolute(3); printRow(rs); rs.relative(-2); printRow(rs); if (conn != null) conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { try {//from w w w.j a va2 s .c o 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:Main.java
public static void main(String[] args) throws Exception { try {//from w ww . jav a2 s . c o 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); String sqlQuery = "SELECT EMPNO, EName, Job, MGR, HIREDATE FROM EMP"; ResultSet rs = stmt.executeQuery(sqlQuery); int rowSize = 0; while (rs.next()) { rowSize++; } System.out.println("Number of Rows in ResultSet is: " + rowSize); if (rowSize == 0) { System.out.println("Since there are no rows, exiting..."); System.exit(0); } int cursorPosition = Math.round(rowSize / 2); System.out.println("Moving to position: " + cursorPosition); rs.absolute(cursorPosition); System.out.println("Name: " + rs.getString(2)); rs.relative(-1); cursorPosition = rs.getRow(); System.out.println("Moving to position: " + cursorPosition); System.out.println("Name: " + rs.getString(2)); System.out.println("Moving to the first row"); while (!rs.isFirst()) { rs.previous(); } System.out.println("Name: " + rs.getString(2)); connection.close(); } catch (Exception e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) throws Exception { try {/* w w w . j a va 2 s.c o 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); String sqlQuery = "SELECT EMPNO, EName, Job, MGR, HIREDATE FROM EMP"; ResultSet rs = stmt.executeQuery(sqlQuery); rs.last(); // Move the cursor backwards through the ResultSet while (rs.previous()) { String nbr = rs.getString(1); String name = rs.getString(2); String job = rs.getString(3); String mgr = rs.getString(4); Timestamp hireDate = rs.getTimestamp(5); System.out.println(name); } rs.close(); stmt.close(); connection.close(); } catch (Exception e) { System.err.println(e); } }
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 av a 2 s . 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); Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); }
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.j a v a 2 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); Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); }
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();// w w w . j a va 2 s .c o m ResultSet rs = st.executeQuery("SELECT * FROM survey"); int rsConcurrency = rs.getConcurrency(); if (rsConcurrency == java.sql.ResultSet.CONCUR_READ_ONLY) { System.out.println("java.sql.ResultSet.CONCUR_READ_ONLY"); } else if (rsConcurrency == java.sql.ResultSet.CONCUR_UPDATABLE) { System.out.println("java.sql.ResultSet.CONCUR_UPDATABLE"); } else { // it is an error } 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);// w w w. jav a 2 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); Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); // Get cursor position int pos = resultSet.getRow(); boolean b = resultSet.isBeforeFirst(); // Move cursor to the first row resultSet.next(); // Get cursor position pos = resultSet.getRow(); b = resultSet.isFirst(); // Move cursor to the last row resultSet.last(); // Get cursor position pos = resultSet.getRow(); b = resultSet.isLast(); // Move cursor past last row resultSet.afterLast(); // Get cursor position pos = resultSet.getRow(); b = resultSet.isAfterLast(); }