Class 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(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
FieldsModifier and TypeFieldDescriptionstatic final ServerSession.ConnectorOpens Oracle sessions; naming this constant is what puts the engine in an application. -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin()Opens a transaction: statements stop committing as they complete.voidbegin(boolean readOnly, TransactionIsolation isolation) Opens a transaction at an isolation level.voidOpens a read-only transaction.voidclose()Closes the connection.voidcommit()Commits the open transaction.static Oracleconnect(String host, int port, String service, String user, String password, String sslMode, String caFile, int timeoutMillis, int socketTimeoutMillis) Opens a session to the serviceserviceon a listener.dialect()The SQL this session's server speaks.intRuns a statement that returns no rows and answers with the number of rows it affected.booleanisClosed()True once the session is closed or its connection was lost.longAlways 0: Oracle reports a generated key throughRETURNING ... INTO.booleanTrue 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.Runs a statement and answers with its rows, each aMapof column name to value in projection order.voidrollback()Rolls the open transaction back.voidSavepoints, under the verbs the other engines use.
-
Field Details
-
CONNECTOR
Opens Oracle sessions; naming this constant is what puts the engine in an application. SeeServerSession.Connector.
-
-
Method Details
-
dialect
Description copied from class:ServerSessionThe SQL this session's server speaks.- Specified by:
dialectin classServerSession
-
ownsTransactionControl
public boolean ownsTransactionControl()Description copied from class:ServerSessionTrue 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:
ownsTransactionControlin classServerSession
-
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
serviceon a listener.sslModeis what the other engines take, except that a connection without TLS is a plain listener port and never an attempt that falls back:requireandverify-fulldemand TLS to a certificate that verifies forhost, andverify-caa chain tocaFilewithout 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 onlydisable, written deliberately; an absent mode orpreferis refused, as SQL Server refuses it.- Throws:
IOException
-
execute
Runs a statement that returns no rows and answers with the number of rows it affected.- Specified by:
executein classServerSession- Throws:
IOException
-
query
Runs a statement and answers with its rows, each aMapof column name to value in projection order. A DML statement withRETURNING ... INTOanswers with one row of the values it returned.- Specified by:
queryin classServerSession- Throws:
IOException
-
begin
Opens a transaction: statements stop committing as they complete.- Specified by:
beginin classServerSession- Throws:
IOException
-
beginReadOnly
Opens a read-only transaction.- Specified by:
beginReadOnlyin classServerSession- Throws:
IOException
-
begin
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:
beginin classServerSession- Throws:
IOException
-
commit
Commits the open transaction.- Specified by:
commitin classServerSession- Throws:
IOException
-
rollback
Rolls the open transaction back.- Specified by:
rollbackin classServerSession- Throws:
IOException
-
savepoint
Savepoints, under the verbs the other engines use. Oracle has nothing to release: a savepoint lasts until its transaction ends.- Specified by:
savepointin classServerSession- Throws:
IOException
-
lastInsertId
public long lastInsertId()Always 0: Oracle reports a generated key throughRETURNING ... INTO.- Specified by:
lastInsertIdin classServerSession
-
close
public void close()Closes the connection. An open transaction is rolled back by the server.- Specified by:
closein classServerSession
-
isClosed
public boolean isClosed()Description copied from class:ServerSessionTrue once the session is closed or its connection was lost.- Specified by:
isClosedin classServerSession
-