Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class ServerDatabase
Known subtypesMySqlDatabase, OracleDatabase, PostgresDatabase, SqlServerDatabase
A Database on a database server rather than a local SQLite file: the base
of PostgresDatabase, MySqlDatabase, SqlServerDatabase and
OracleDatabase.
Pick the engine by constructing its class. Only the engines an application names are in it; there is no driver lookup and no URL to parse.
String password = Preferences.get("dbPassword", "");
Database db = new PostgresDatabase("db.example.com", 5432, "inventory", "app", password);
try {
Cursor c = db.executeQuery("SELECT id, name FROM item WHERE price < ?", 10.0);
while (c.next()) {
Row r = c.getRow();
Log.p(r.getLong(0) + " " + r.getString(1));
}
c.close();
} finally {
db.close();
}Every call waits on the network, so none may run on the EDT: they throw
there. Statements use ? for parameters on every engine. Rows are read whole
when the query returns, so a cursor can move in both directions.
The connection is plain TCP. This platform’s sockets have no TLS, so
sslMode must be disable, written out: the password and every row cross the
network unencrypted, so nothing chooses that for the caller. Any other mode,
prefer included, is refused rather than quietly downgraded. Reach a server over a network you trust, or
through a tunnel.
Constructors
Methods
Inherited fields
Inherited methods
From Database
isCustomPathSupported, isLegacyBehavior, setLegacyBehavior, openOrCreate, exists, delete, isDatabaseBeingDeleted, openDatabaseCount, getDatabasePath, openOrCreate, isEncryptionSupported, isEncrypted, encrypt, decrypt, forgetManagedKey, beforeFirst, count, isBlobQueryParameterSupported, changeKey, wasNull, supportsWasNull, isInTransaction, toPragmaLiteral, noteScriptTransactionControl, hasAttachments, reserveAttachments, reserveAttachments, requireAttachmentsHeld, noteConnectionClosed, noteFirstStatementTransactionControl, noteEngineTransactionState, transactionControlKeyword, beginTransactionMode, requireQueryStatement, normalizeDatabaseKey, normalizeDatabasePathKey, registerOpenDatabase, releaseOpenDatabase, requireSoleConnectionForKeyChange, releaseKeyChangeClaim, checkNoTransactionForKeyChange, supportsNestedTransactions, checkBeginTransaction, checkEndTransaction, markTransactionEnded, abandonFailedCommit, coerceToText
Constructor details
ServerDatabase
protected ServerDatabase(ServerSession.Connector connector, String host, int port, String database, String user, String password, String sslMode, int timeoutMillis)
throws IOExceptionParameters
connectorServerSession.Connector- the engine, for example
Postgres.CONNECTOR hostString- Not documented.
portint- Not documented.
databaseString- Not documented.
userString- Not documented.
passwordString- Not documented.
sslModeStringdisable; anything else is refusedtimeoutMillisint- how long connecting may take, and each wait for the server after it (signing in, a query’s reply); 0 for no limit
Throws
Method details
getDialect
public Dialect getDialect()beginTransaction
public void beginTransaction()
throws IOExceptionStarts a transaction.
Transactions are flat. Calling this while a transaction is already open throws, and committing or rolling back returns the connection to autocommit. Closing a database with an open transaction rolls it back.
Throws
IOException- if the database is not open, or a transaction is already in progress
commitTransaction
public void commitTransaction()
throws IOExceptionCommits current transaction
NOTE: Not supported in Javascript port. This method will do nothing when running in Javascript.
Throws
IOException- if database is not opened or transaction was not started
rollbackTransaction
public void rollbackTransaction()
throws IOExceptionRolls back current transaction
NOTE: Not supported in Javascript port. This method will do nothing when running in Javascript.
Throws
IOException- if database is not opened or transaction was not started
close
public void close()Throws
isClosed
public boolean isClosed()execute
public void execute(String sql)
throws IOExceptionParameters
sqlString- the sql to execute
Throws
execute
public void execute(String sql, String[] params)
throws IOExceptionParameters
sqlString- the sql to execute
paramsString[]- to bind to the query where the ‘?’ exists
Throws
execute
public void execute(String sql, Object... params)
throws IOExceptionParameters
sqlString- the sql to execute
paramsObject...- to bind to the query where the ‘?’ exists, supported object types are String, byte[], Double, Long and null
Throws
executeUpdate
public int executeUpdate(String sql, Object... params)
throws IOExceptionThrows
executeQuery
public Cursor executeQuery(String sql)
throws IOExceptionParameters
sqlString- the sql to execute
Returns
Throws
executeQuery
public Cursor executeQuery(String sql, String[] params)
throws IOExceptionParameters
sqlString- the sql to execute
paramsString[]- to bind to the query where the ‘?’ exists
Returns
Throws
executeQuery
public Cursor executeQuery(String sql, Object... params)
throws IOExceptionParameters
sqlString- the sql to execute
paramsObject...- to bind to the query where the ‘?’ exists, supported object types are String, byte[], Double, Long and null