OracleDataSource ods = new OracleDataSource(); ods.setUser(DB_USER)); ods.setPassword(DB_PASSWORD); ods.setURL(jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename)))); // New AutoClosable syntax applicable to connection. This syntax will // close the connection automatically try (OracleConnection connection = (OracleConnection) (ods.getConnection())) { // Statement and ResultSet are AutoClosable by this syntax try (Statement statement = connection.createStatement()) { try (ResultSet resultSet = statement.executeQuery("select sysdate from dual")) { while (resultSet.next()) System.out.print("Today's Date is: " + resultSet.getString(1)); } } }
int primaryKeyId = getNextPrimaryKeyId(); PreparedStatement stmt1 = conn.prepareStatement(" insert into docTable values (?, ?, empty_blob()) "); stmt1.setInt(1, primaryKeyId ); stmt1.setString(2, getDocumentTitle()); stmt1.executeUpdate(); PreparedStatement stmt2 = conn.prepareStatement(" select doc from docTable where id = ? for update "); stmt2.setInt(1, primaryKeyId); stmt2.execute(); OracleResultSet rset = (OracleResultSet)stmt2.getResultSet(); if (rset.next()) { BLOB document = rset.getBLOB("doc"); document.trim(0); OutputStream os = document.getBinaryOutputStream(); os.write(getDocumentToBeWrittenToDb()); os.flush; os.close; }
/** * Returns the bytes from a result set * * @param res * The ResultSet to read from * @param columnName * The name of the column to read from * * @return The byte value from the column */ public byte[] getBytesFromResultset(ResultSet res, String columnName) throws SQLException { // read the bytes from an oracle blob oracle.sql.BLOB blob = ((OracleResultSet) res).getBLOB(columnName); byte[] content = new byte[(int) blob.length()]; content = blob.getBytes(1, (int) blob.length()); return content; }
.getConnection("connstr", connectionProps); Statement stmt = conn.createStatement(); oracle.sql.ARRAY arr2 = new oracle.sql.ARRAY(desc2, conn, northEastRegion); PreparedStatement ps = conn.prepareStatement(str); ps.setArray(1, arr2); ps.executeQuery();
this.register = connection.registerDatabaseChangeNotification(properties); final List<DatabaseField> fields = new ArrayList<DatabaseField>(); fields.add(new DatabaseField(ROWID)); OracleStatement statement = (OracleStatement)connection.createStatement(); statement.setDatabaseChangeRegistration(this.register); try {
/** * INTERNAL: * Remove the event listener from the database. */ public void remove(Session session) { if (this.register == null) { return; } AbstractSession databaseSession = (AbstractSession)session; Accessor accessor = databaseSession.getAccessor(); accessor.incrementCallCount(databaseSession); try { OracleConnection connection = (OracleConnection)databaseSession.getServerPlatform().unwrapConnection(accessor.getConnection()); databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_unregister"); try { connection.unregisterDatabaseChangeNotification(this.register); } catch (SQLException exception) { throw DatabaseException.sqlException(exception, databaseSession.getAccessor(), databaseSession, false); } } finally { accessor.decrementCallCount(); } }
blob = ors.getBLOB(1);
try (Connection conn = ConnManager.getConnection();) { if (conn.isWrapperFor(OracleConnection.class)) { try (OracleConnection oracleConnection = conn.unwrap(OracleConnection.class); Statement stmt = oracleConnection.createStatement()) { ResultSet rs = stmt.executeQuery("select regid,callback from USER_CHANGE_NOTIFICATION_REGS"); while (rs.next()) { long regid = rs.getLong(1); String callback = rs.getString(2); ((OracleConnection) stmt.getConnection()).unregisterDatabaseChangeNotification(regid, callback); } } } } catch (SQLException ex) { Logger.getLogger(TableBase.class.getName()).log(Level.SEVERE, null, ex); }