Class Oracle


public final class Oracle extends ServerSession

An Oracle Database client speaking TNS and TTC, the protocol of Oracle's own "thin" drivers. Oracle Database 19c and later.

Oracle db = Oracle.connect("db.internal", 1521, "FREEPDB1", "app", "secret",
        "disable", null, 10000, 0);
List rows = db.query("SELECT id, name FROM users WHERE id = :1", new Object[] {7L});
Statements

Parameters are written :1, :2 and so on and bound by number: the same number used twice binds the same value twice. A DML statement that ends in RETURNING ... INTO :n answers query(String, Object[]) with one row holding what it returned. Outside a transaction every statement commits as it completes, as on the other engines.

Encryption

sslmode require, verify-full and verify-ca connect over TLS (TCPS), which is a listener port of its own, usually 2484. Without TLS the password still never crosses the network: the O5LOGON exchange proves it with keys derived from it. Oracle's Native Network Encryption is not implemented, and neither are wallets.

Values

A NUMBER that is a whole number within the range of a long arrives as Long, any other NUMBER as its exact digits in a String. BINARY_DOUBLE and BINARY_FLOAT arrive as Double, RAW and BLOB as byte[], text and CLOB as String, and DATE and TIMESTAMP as yyyy-MM-dd HH:mm:ss[.fff].

  • Nested Class Summary

    Nested classes/interfaces inherited from class ServerSession

    ServerSession.Connector
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Opens Oracle sessions; naming this constant is what puts the engine in an application.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Opens a transaction: statements stop committing as they complete.
    void
    begin(boolean readOnly, TransactionIsolation isolation)
    Opens a transaction at an isolation level.
    void
    Opens a read-only transaction.
    void
    Closes the connection.
    void
    Commits the open transaction.
    static Oracle
    connect(String host, int port, String service, String user, String password, String sslMode, String caFile, int timeoutMillis, int socketTimeoutMillis)
    Opens a session to the service service on a listener.
    The SQL this session's server speaks.
    int
    execute(String sql, Object[] params)
    Runs a statement that returns no rows and answers with the number of rows it affected.
    boolean
    True once the session is closed or its connection was lost.
    long
    Always 0: Oracle reports a generated key through RETURNING ... INTO.
    boolean
    True when beginning, committing and rolling back are protocol requests or session state of this client's own, rather than statements a caller could equally run.
    query(String sql, Object[] params)
    Runs a statement and answers with its rows, each a Map of column name to value in projection order.
    void
    Rolls the open transaction back.
    void
    savepoint(String verb, String name)
    Savepoints, under the verbs the other engines use.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • dialect

      public Dialect dialect()
      Description copied from class: ServerSession
      The SQL this session's server speaks.
      Specified by:
      dialect in class ServerSession
    • ownsTransactionControl

      public boolean ownsTransactionControl()
      Description copied from class: ServerSession
      True when beginning, committing and rolling back are protocol requests or session state of this client's own, rather than statements a caller could equally run.
      Specified by:
      ownsTransactionControl in class ServerSession
    • connect

      public static Oracle connect(String host, int port, String service, String user, String password, String sslMode, String caFile, int timeoutMillis, int socketTimeoutMillis) throws IOException

      Opens a session to the service service on a listener.

      sslMode is what the other engines take, except that a connection without TLS is a plain listener port and never an attempt that falls back: require and verify-full demand TLS to a certificate that verifies for host, and verify-ca a chain to caFile without the name. Without TLS the password is still never sent, but an active attacker can pick the verifier and its iteration count and crack the answer offline, and every row crosses in the clear, so plaintext is only disable, written deliberately; an absent mode or prefer is refused, as SQL Server refuses it.

      Throws:
      IOException
    • execute

      public int execute(String sql, Object[] params) throws IOException
      Runs a statement that returns no rows and answers with the number of rows it affected.
      Specified by:
      execute in class ServerSession
      Throws:
      IOException
    • query

      public List query(String sql, Object[] params) throws IOException
      Runs a statement and answers with its rows, each a Map of column name to value in projection order. A DML statement with RETURNING ... INTO answers with one row of the values it returned.
      Specified by:
      query in class ServerSession
      Throws:
      IOException
    • begin

      public void begin() throws IOException
      Opens a transaction: statements stop committing as they complete.
      Specified by:
      begin in class ServerSession
      Throws:
      IOException
    • beginReadOnly

      public void beginReadOnly() throws IOException
      Opens a read-only transaction.
      Specified by:
      beginReadOnly in class ServerSession
      Throws:
      IOException
    • begin

      public void begin(boolean readOnly, TransactionIsolation isolation) throws IOException
      Opens a transaction at an isolation level. Oracle has two: READ COMMITTED, its default, and SERIALIZABLE. REPEATABLE READ is given SERIALIZABLE, the stronger of them, and READ UNCOMMITTED is READ COMMITTED, since Oracle never reads uncommitted data.
      Specified by:
      begin in class ServerSession
      Throws:
      IOException
    • commit

      public void commit() throws IOException
      Commits the open transaction.
      Specified by:
      commit in class ServerSession
      Throws:
      IOException
    • rollback

      public void rollback() throws IOException
      Rolls the open transaction back.
      Specified by:
      rollback in class ServerSession
      Throws:
      IOException
    • savepoint

      public void savepoint(String verb, String name) throws IOException
      Savepoints, under the verbs the other engines use. Oracle has nothing to release: a savepoint lasts until its transaction ends.
      Specified by:
      savepoint in class ServerSession
      Throws:
      IOException
    • lastInsertId

      public long lastInsertId()
      Always 0: Oracle reports a generated key through RETURNING ... INTO.
      Specified by:
      lastInsertId in class ServerSession
    • close

      public void close()
      Closes the connection. An open transaction is rolled back by the server.
      Specified by:
      close in class ServerSession
    • isClosed

      public boolean isClosed()
      Description copied from class: ServerSession
      True once the session is closed or its connection was lost.
      Specified by:
      isClosed in class ServerSession