Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class Oracle

  1. Object
  2. ServerSession
  3. Oracle

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 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].

Fields

public static final ServerSession.Connector CONNECTOROpens Oracle sessions; naming this constant is what puts the engine in an application.

Methods

public Dialect dialect()The SQL this session’s server speaks.
public boolean ownsTransactionControl()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.
public static Oracle connect(String host, int port, String service, String user, String password, String sslMode, String caFile, int timeoutMillis, int socketTimeoutMillis) throws IOExceptionOpens a session to the service service on a listener.
public int execute(String sql, Object[] params) throws IOExceptionRuns a statement that returns no rows and answers with the number of rows it affected.
public List query(String sql, Object[] params) throws IOExceptionRuns a statement and answers with its rows, each a Map of column name to value in projection order.
public void begin() throws IOExceptionOpens a transaction: statements stop committing as they complete.
public void beginReadOnly() throws IOExceptionOpens a read-only transaction.
public void begin(boolean readOnly, TransactionIsolation isolation) throws IOExceptionOpens a transaction at an isolation level.
public void commit() throws IOExceptionCommits the open transaction.
public void rollback() throws IOExceptionRolls the open transaction back.
public void savepoint(String verb, String name) throws IOExceptionSavepoints, under the verbs the other engines use.
public long lastInsertId()Always 0: Oracle reports a generated key through RETURNING ... INTO.
public void close()Closes the connection.
public boolean isClosed()True once the session is closed or its connection was lost.

Inherited nested types

Inherited methods

Field details

CONNECTOR

public static final ServerSession.Connector CONNECTOR
Opens Oracle sessions; naming this constant is what puts the engine in an application. See ServerSession.Connector.

Method details

dialect

public Dialect dialect()
The SQL this session’s server speaks.

ownsTransactionControl

public boolean ownsTransactionControl()
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.

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.

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.

Returns

the number of rows it changed

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.

begin

public void begin() throws IOException
Opens a transaction: statements stop committing as they complete.

beginReadOnly

public void beginReadOnly() throws IOException
Opens a read-only transaction.

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.

commit

public void commit() throws IOException
Commits the open transaction.

rollback

public void rollback() throws IOException
Rolls the open transaction back.

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.

lastInsertId

public long lastInsertId()
Always 0: Oracle reports a generated key through RETURNING ... INTO.

close

public void close()
Closes the connection. An open transaction is rolled back by the server.

isClosed

public boolean isClosed()
True once the session is closed or its connection was lost.