Class MySql

java.lang.Object
com.codename1.backend.sql.MySql

public final class MySql extends Object

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 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.

      Throws:
      IOException
    • execute

      public int execute(String sql, Object[] params) throws IOException
      Throws:
      IOException
    • query

      public List query(String sql, Object[] params) throws IOException
      Throws:
      IOException
    • begin

      public void begin() throws IOException
      Opens a transaction. See command(String) for why this is not execute.
      Throws:
      IOException
    • commit

      public void commit() throws IOException
      Throws:
      IOException
    • rollback

      public void rollback() throws IOException
      Throws:
      IOException
    • beginReadOnly

      public void beginReadOnly() throws IOException
      Opens a transaction that refuses writes.
      Throws:
      IOException
    • 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.
      Throws:
      IOException
    • lastInsertId

      public long lastInsertId()
    • close

      public void close()
    • isClosed

      public boolean isClosed()