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 MySql
- Object
- ServerSession
- 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.
The exception is a statement the server refuses to prepare, which binds
nothing and goes as text; see command.
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.
Fields
public static final ServerSession.Connector CONNECTOR | Opens MySql sessions; naming this constant is what puts the engine in an application. |
Methods
Inherited nested types
Inherited methods
Field details
CONNECTOR
public static final ServerSession.Connector CONNECTORServerSession.Connector.Method details
dialect
public Dialect dialect()ownsTransactionControl
public boolean ownsTransactionControl()isMariaDb
public boolean isMariaDb()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 IOExceptionConnects, optionally upgrades to TLS, and authenticates.
sslMode is “require”, “prefer” or “disable”, as in Postgres.
Throws
execute
public int execute(String sql, Object[] params)
throws IOExceptionReturns
Throws
query
public List query(String sql, Object[] params)
throws IOExceptionMap rows keyed by column label, in column order.Throws
begin
public void begin()
throws IOExceptioncommand for why this is not execute.Throws
commit
public void commit()
throws IOExceptionThrows
rollback
public void rollback()
throws IOExceptionThrows
beginReadOnly
public void beginReadOnly()
throws IOExceptionThrows
begin
public void begin(boolean readOnly, TransactionIsolation isolation)
throws IOExceptionThrows
savepoint
public void savepoint(String verb, String name)
throws IOExceptionbegin. 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.Throws
lastInsertId
public long lastInsertId()close
public void close()isClosed
public boolean isClosed()