List of usage examples for java.sql ResultSet TYPE_SCROLL_SENSITIVE
int TYPE_SCROLL_SENSITIVE
To view the source code for java.sql ResultSet TYPE_SCROLL_SENSITIVE.
Click Source Link
ResultSet
object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet
. From source file:orca.registry.DatabaseOperations.java
License:asdf
/** * Get a map of controller as map indexed by url * @return/*from ww w . j a v a2s .com*/ */ public List<Map<String, String>> queryControllerList() { List<Map<String, String>> result = new ArrayList<Map<String, String>>(); log.debug("Inside DatabaseOperations: queryControllerList() - query for controllers"); Connection conn = null; try { //System.out.println("Trying to get a new instance"); log.debug("Inside DatabaseOperations: queryControllerList() - Trying to get a new instance"); Class.forName("com.mysql.jdbc.Driver").newInstance(); //System.out.println("Trying to get a database connection"); log.debug("Inside DatabaseOperations: queryControllerList() - Trying to get a database connection"); conn = DriverManager.getConnection(url, userName, password); //System.out.println ("Database connection established"); log.debug("Inside DatabaseOperations: queryControllerList() - Database connection established"); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet srs = stmt.executeQuery("SELECT * FROM Controllers ORDER BY ctrl_name"); while (srs.next()) { HashMap<String, String> tmpMap = new HashMap<String, String>(); //`img_simple_name` , `img_ver` , `img_neuca_ver`, `img_url`, `img_hash`, `img_owner`, `img_description`, `img_date`, `img_default` nonNullMapPut(tmpMap, CTRL_NAME, srs.getString("ctrl_name")); nonNullMapPut(tmpMap, CTRL_URL, srs.getString("ctrl_url")); nonNullMapPut(tmpMap, CTRL_DESCRIPTION, srs.getString("ctrl_description")); nonNullMapPut(tmpMap, CTRL_ENABLED, (srs.getBoolean("ctrl_enabled") ? "True" : "False")); // save the result result.add(tmpMap); } srs.close(); } catch (Exception e) { //System.err.println ("Cannot query the database server"); log.error( "Inside DatabaseOperations: queryControllerList() - Exception while querying the database server: " + e.toString()); } finally { if (conn != null) { try { conn.close(); //System.out.println ("Database connection terminated"); log.debug("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } return result; }
From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java
public void getUpdatableResultSet() { try {/*from w w w. ja v a 2 s. c om*/ Statement stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); updatableResultSet = stmt2.executeQuery("SELECT ID, " + keyObservation + ", " + keyPriority + ", COMMENTS FROM " + targetTableName + " WHERE ID = " + resultSet.getString("ID")); updatableResultSet.first(); } catch (SQLException err) { System.out.println(err.getMessage()); } }
From source file:orca.registry.DatabaseOperations.java
License:asdf
/** * Get a map of images as map indexed by hash * @return// www . j a va 2 s . c o m */ public List<Map<String, String>> queryImageList() { List<Map<String, String>> result = new ArrayList<Map<String, String>>(); log.debug("Inside DatabaseOperations: queryImageMap() - query for images"); Connection conn = null; try { //System.out.println("Trying to get a new instance"); log.debug("Inside DatabaseOperations: queryImageMap() - Trying to get a new instance"); Class.forName("com.mysql.jdbc.Driver").newInstance(); //System.out.println("Trying to get a database connection"); log.debug("Inside DatabaseOperations: queryImageMap() - Trying to get a database connection"); conn = DriverManager.getConnection(url, userName, password); //System.out.println ("Database connection established"); log.debug("Inside DatabaseOperations: queryImageMap() - Database connection established"); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet srs = stmt.executeQuery("SELECT * FROM Images ORDER BY img_simple_name"); while (srs.next()) { HashMap<String, String> tmpMap = new HashMap<String, String>(); //`img_simple_name` , `img_ver` , `img_neuca_ver`, `img_url`, `img_hash`, `img_owner`, `img_description`, `img_date`, `img_default` nonNullMapPut(tmpMap, IMAGE_NAME, srs.getString("img_simple_name")); nonNullMapPut(tmpMap, IMAGE_VERSION, srs.getString("img_ver")); nonNullMapPut(tmpMap, IMAGE_NEUCA_VERSION, srs.getString("img_neuca_ver")); nonNullMapPut(tmpMap, IMAGE_URL, srs.getString("img_url")); nonNullMapPut(tmpMap, IMAGE_HASH, srs.getString("img_hash")); nonNullMapPut(tmpMap, IMAGE_OWNER, srs.getString("img_owner")); nonNullMapPut(tmpMap, IMAGE_DESCRIPTION, srs.getString("img_description")); nonNullMapPut(tmpMap, IMAGE_DATE, srs.getString("img_date")); nonNullMapPut(tmpMap, IMAGE_DEFAULT, (srs.getBoolean("img_default") ? "True" : "False")); // save the result result.add(tmpMap); } srs.close(); } catch (Exception e) { //System.err.println ("Cannot query the database server"); log.error("Inside DatabaseOperations: queryImages() - Exception while querying the database server: " + e.toString()); } finally { if (conn != null) { try { conn.close(); //System.out.println ("Database connection terminated"); log.debug("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } return result; }
From source file:orca.registry.DatabaseOperations.java
License:asdf
/** * Get default image(s) (if exists)/* w w w.ja va 2s. co m*/ * @return */ public List<Map<String, String>> queryDefaultImage() { log.debug("Inside DatabaseOperations: queryImageMap() - query for images"); Connection conn = null; List<Map<String, String>> result = new ArrayList<Map<String, String>>(); try { //System.out.println("Trying to get a new instance"); log.debug("Inside DatabaseOperations: queryImageMap() - Trying to get a new instance"); Class.forName("com.mysql.jdbc.Driver").newInstance(); //System.out.println("Trying to get a database connection"); log.debug("Inside DatabaseOperations: queryImageMap() - Trying to get a database connection"); conn = DriverManager.getConnection(url, userName, password); //System.out.println ("Database connection established"); log.debug("Inside DatabaseOperations: queryImageMap() - Database connection established"); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet srs = stmt.executeQuery("SELECT * FROM Images WHERE img_default=1 ORDER BY img_simple_name"); while (srs.next()) { HashMap<String, String> tmpMap = new HashMap<String, String>(); //`img_simple_name` , `img_ver` , `img_neuca_ver`, `img_url`, `img_hash`, `img_owner`, `img_description`, `img_date` nonNullMapPut(tmpMap, IMAGE_NAME, srs.getString("img_simple_name")); nonNullMapPut(tmpMap, IMAGE_VERSION, srs.getString("img_ver")); nonNullMapPut(tmpMap, IMAGE_NEUCA_VERSION, srs.getString("img_neuca_ver")); nonNullMapPut(tmpMap, IMAGE_URL, srs.getString("img_url")); nonNullMapPut(tmpMap, IMAGE_HASH, srs.getString("img_hash")); nonNullMapPut(tmpMap, IMAGE_OWNER, srs.getString("img_owner")); nonNullMapPut(tmpMap, IMAGE_DESCRIPTION, srs.getString("img_description")); nonNullMapPut(tmpMap, IMAGE_DATE, srs.getString("img_date")); // save the result result.add(tmpMap); } srs.close(); } catch (Exception e) { //System.err.println ("Cannot query the database server"); log.error("Inside DatabaseOperations: queryImages() - Exception while querying the database server: " + e.toString()); } finally { if (conn != null) { try { conn.close(); //System.out.println ("Database connection terminated"); log.debug("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } return result; }
From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java
private void setUpActiveLearningTempTable() throws SQLException { Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); try {/*from ww w . j a v a 2 s . c o m*/ stmt1.execute("DROP TABLE " + targetTableName + "_TEMPAL"); } catch (SQLException ex) { System.out.println(ex); System.out.println("Drop of temp table failed. It probably doesn't exist yet"); } stmt1.execute("select t1.id into " + targetTableName + "_TEMPAL \n " + " FROM " + targetTableName + " t1 \n " + " inner join \n " + " ( \n " + " select distinct contextString, min(id) as id from " + targetTableName + " \n " + " group by contextString \n " + " ) as b\n " + " on t1.contextString = b.contextString\n " + " and t1.id = b.id "); }
From source file:org.apache.hive.jdbc.TestJdbcDriver2.java
/** * Negative Test for cursor repositioning to start of resultset * Verify unsupported JDBC resultset attributes * @throws Exception/*from ww w . ja v a 2 s . c o m*/ */ @Test public void testUnsupportedFetchTypes() throws Exception { try { con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); fail("createStatement with TYPE_SCROLL_SENSITIVE should fail"); } catch (SQLException e) { assertEquals("HYC00", e.getSQLState().trim()); } try { con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); fail("createStatement with CONCUR_UPDATABLE should fail"); } catch (SQLException e) { assertEquals("HYC00", e.getSQLState().trim()); } }
From source file:net.starschema.clouddb.jdbc.BQDatabaseMetadata.java
/** * <p>/*w ww. j a v a 2 s . c o m*/ * <h1>Implementation Details:</h1><br> * Returns false * </p> */ @Override public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { if (ResultSet.TYPE_FORWARD_ONLY == type) { if (ResultSet.CONCUR_READ_ONLY == concurrency) { return true; } if (ResultSet.CONCUR_UPDATABLE == concurrency) { return false; } } if (ResultSet.TYPE_SCROLL_INSENSITIVE == type) { if (ResultSet.CONCUR_READ_ONLY == concurrency) { return true; } if (ResultSet.CONCUR_UPDATABLE == concurrency) { return false; } } if (ResultSet.TYPE_SCROLL_SENSITIVE == type) { if (ResultSet.CONCUR_READ_ONLY == concurrency) { return true; } if (ResultSet.CONCUR_UPDATABLE == concurrency) { return false; } } return false; }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
public void updateBlob(Select sel, JDBCStore store, InputStream is) throws SQLException { SQLBuffer sql = sel.toSelect(true, store.getFetchConfiguration()); ResultSet res = null;//w w w . ja v a 2 s . c o m Connection conn = store.getConnection(); PreparedStatement stmnt = null; try { stmnt = sql.prepareStatement(conn, store.getFetchConfiguration(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); setTimeouts(stmnt, store.getFetchConfiguration(), true); res = stmnt.executeQuery(); if (!res.next()) { throw new InternalException(_loc.get("stream-exception")); } Blob blob = res.getBlob(1); OutputStream os = blob.setBinaryStream(1); copy(is, os); os.close(); res.updateBlob(1, blob); res.updateRow(); } catch (IOException ioe) { throw new StoreException(ioe); } finally { if (res != null) try { res.close(); } catch (SQLException e) { } if (stmnt != null) try { stmnt.close(); } catch (SQLException e) { } if (conn != null) try { conn.close(); } catch (SQLException e) { } } }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
public void updateClob(Select sel, JDBCStore store, Reader reader) throws SQLException { SQLBuffer sql = sel.toSelect(true, store.getFetchConfiguration()); ResultSet res = null;/*from w ww. j a v a2 s .co m*/ Connection conn = store.getConnection(); PreparedStatement stmnt = null; try { stmnt = sql.prepareStatement(conn, store.getFetchConfiguration(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); setTimeouts(stmnt, store.getFetchConfiguration(), true); res = stmnt.executeQuery(); if (!res.next()) { throw new InternalException(_loc.get("stream-exception")); } Clob clob = res.getClob(1); if (clob != null) { Writer writer = clob.setCharacterStream(1); copy(reader, writer); writer.close(); res.updateClob(1, clob); res.updateRow(); } } catch (IOException ioe) { throw new StoreException(ioe); } finally { if (res != null) try { res.close(); } catch (SQLException e) { } if (stmnt != null) try { stmnt.close(); } catch (SQLException e) { } if (conn != null) try { conn.close(); } catch (SQLException e) { } } }