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.
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.
-
Method Summary
Modifier and TypeMethodDescriptionvoidbegin()Opens a transaction.voidclose()voidcommit()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.intbooleanisClosed()booleanSeemariaDb.longvoidrollback()
-
Method Details
-
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
- Throws:
IOException
-
query
- Throws:
IOException
-
begin
Opens a transaction. Seecommand(String)for why this is notexecute.- Throws:
IOException
-
commit
- Throws:
IOException
-
rollback
- Throws:
IOException
-
lastInsertId
public long lastInsertId() -
close
public void close() -
isClosed
public boolean isClosed()
-