Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class MySql

  1. Object
  2. MySql

A MySQL client speaking the client/server protocol directly, for the same reason as Postgres: a translated server binary has no JDBC.

Everything goes through prepared statements (COM_STMT_PREPARE / EXECUTE) and therefore through MySQL’s BINARY result format. That is more code than sending COM_QUERY text, and it is the only way to bind a parameter – a text-protocol client has to build SQL by concatenation, and this API refuses to offer that.

Authentication covers what is actually deployed: caching_sha2_password (the MySQL 8 default) and mysql_native_password (5.7 and MariaDB). The caching_sha2 FULL exchange – which the server demands the first time a password is used, before its cache is warm – sends the password to the server, so this client does it only on a TLS connection and says so rather than falling back to the RSA-wrapped variant, which would be a second cryptographic path to get wrong.

Methods

public boolean isMariaDb()See mariaDb.
public static MySql connect(String host, int port, String database, String user, String password, String sslMode, String caFile, int timeoutMillis, int socketTimeoutMillis) throws IOExceptionConnects, optionally upgrades to TLS, and authenticates.
public int execute(String sql, Object[] params) throws IOException
public List query(String sql, Object[] params) throws IOException
public void begin() throws IOExceptionOpens a transaction.
public void commit() throws IOException
public void rollback() throws IOException
public void beginReadOnly() throws IOExceptionOpens a transaction that refuses writes.
public void begin(boolean readOnly, Isolation isolation) throws IOExceptionUses a next-transaction setting, never a session default.
public void savepoint(String verb, String name) throws IOExceptionSavepoint control, through the text protocol for the same reason as begin.
public long lastInsertId()
public void close()
public boolean isClosed()

Inherited methods

Method details

isMariaDb

public boolean isMariaDb()
See mariaDb.

connect

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

Connects, optionally upgrades to TLS, and authenticates.

sslMode is “require”, “prefer” or “disable”, as in Postgres.

execute

public int execute(String sql, Object[] params) throws IOException

query

public List query(String sql, Object[] params) throws IOException

begin

public void begin() throws IOException
Opens a transaction. See command for why this is not execute.

commit

public void commit() throws IOException

rollback

public void rollback() throws IOException

beginReadOnly

public void beginReadOnly() throws IOException
Opens a transaction that refuses writes.

begin

public void begin(boolean readOnly, Isolation isolation) throws IOException
Uses a next-transaction setting, never a session default. The enum keeps arbitrary SQL out of the text-protocol transaction control path.

savepoint

public void savepoint(String verb, String name) throws IOException
Savepoint control, through the text protocol for the same reason as begin. The name is checked to be a plain identifier here as well as by the caller, because this is the one text-protocol entry point that takes a value at all.

lastInsertId

public long lastInsertId()

close

public void close()

isClosed

public boolean isClosed()