Class 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(String).
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class ServerSession
ServerSession.Connector -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ServerSession.ConnectorOpens MySql sessions; naming this constant is what puts the engine in an application. -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin()Opens a transaction.voidbegin(boolean readOnly, TransactionIsolation isolation) Uses a next-transaction setting, never a session default.voidOpens a transaction that refuses writes.voidclose()Closes the session; closing twice does nothing.voidcommit()Commits the transaction.static MySqlconnect(String host, int port, String database, String user, String password, String sslMode, String caFile, int timeoutMillis, int socketTimeoutMillis) Connects, optionally upgrades to TLS, and authenticates.dialect()The SQL this session's server speaks.intRuns a statement that returns no rows.booleanisClosed()True once the session is closed or its connection was lost.booleanSeemariaDb.longThe key the last INSERT generated, for an engine that reports one that way; 0 otherwise.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 query: a list ofMaprows keyed by column label, in column order.voidrollback()Rolls the transaction back.voidSavepoint control, through the text protocol for the same reason asbegin().
-
Field Details
-
CONNECTOR
Opens MySql 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
-
isMariaDb
public boolean isMariaDb()SeemariaDb. -
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.
sslModeis "require", "prefer" or "disable", as inPostgres.- Throws:
IOException
-
execute
Description copied from class:ServerSessionRuns a statement that returns no rows.
Returns
the number of rows it changed
- Specified by:
executein classServerSession- Throws:
IOException
-
query
Description copied from class:ServerSessionRuns a query: a list ofMaprows keyed by column label, in column order.- Specified by:
queryin classServerSession- Throws:
IOException
-
begin
Opens a transaction. Seecommand(String)for why this is notexecute.- Specified by:
beginin classServerSession- Throws:
IOException
-
commit
Description copied from class:ServerSessionCommits the transaction.- Specified by:
commitin classServerSession- Throws:
IOException
-
rollback
Description copied from class:ServerSessionRolls the transaction back.- Specified by:
rollbackin classServerSession- Throws:
IOException
-
beginReadOnly
Opens a transaction that refuses writes.- Specified by:
beginReadOnlyin classServerSession- Throws:
IOException
-
begin
Uses a next-transaction setting, never a session default. The enum keeps arbitrary SQL out of the text-protocol transaction control path.- Specified by:
beginin classServerSession- Throws:
IOException
-
savepoint
Savepoint control, through the text protocol for the same reason asbegin(). 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.- Specified by:
savepointin classServerSession- Throws:
IOException
-
lastInsertId
public long lastInsertId()Description copied from class:ServerSessionThe key the last INSERT generated, for an engine that reports one that way; 0 otherwise.- Specified by:
lastInsertIdin classServerSession
-
close
public void close()Description copied from class:ServerSessionCloses the session; closing twice does nothing.- 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
-