CREATE TABLECREATE TABLE is a DDL (Data Definition Language) operation that creates a new table.
The following example program creates the test.contacts table, which is described in the example setup. If you already created the table, the example program should still work because it uses the IFNOTEXISTS clause for CREATE TABLECREATE TABLE. The example, could be used as an alternative to running a CREATE TABLECREATE TABLE DDL statement in MariaDB Client.
importjava.sql.*;importjava.util.Properties;publicclassApp{publicstaticvoidmain(String[]argv){PropertiesconnConfig=newProperties();connConfig.setProperty("user","db_user");connConfig.setProperty("password","db_user_password");try(Connectionconn=DriverManager.getConnection("jdbc:mariadb://HOST:PORT",connConfig)){try(Statementstmt=conn.createStatement()){stmnt.execute("CREATE TABLE IF NOT EXISTS test.contacts ("+" id INT PRIMARY KEY AUTO_INCREMENT,"+" first_name VARCHAR(25),"+" last_name VARCHAR(25),"+" email VARCHAR(100)"+") ENGINE=InnoDB;");}}catch(Exceptione){e.printStackTrace();}}}
In MariaDB Connector/J 3.0, TLS is enabled for connections to SkySQL using the sslMode parameter.
importjava.sql.*;importjava.util.Properties;publicclassApp{publicstaticvoidmain(String[]argv){PropertiesconnConfig=newProperties();connConfig.setProperty("user","db_user");connConfig.setProperty("password","db_user_password");connConfig.setProperty("sslMode","verify-full");connConfig.setProperty("serverSslCert","/path/to/skysql_chain.pem");try(Connectionconn=DriverManager.getConnection("jdbc:mariadb://HOST:PORT",connConfig)){try(Statementstmt=conn.createStatement()){stmnt.execute("CREATE TABLE IF NOT EXISTS test.contacts ("+" id INT PRIMARY KEY AUTO_INCREMENT,"+" first_name VARCHAR(25),"+" last_name VARCHAR(25),"+" email VARCHAR(100)"+") ENGINE=InnoDB;");}}catch(Exceptione){e.printStackTrace();}}}
In MariaDB Connector/J 2.7 and before, TLS is enabled for connections to SkySQL using the useSsl parameter.
importjava.sql.*;importjava.util.Properties;publicclassApp{publicstaticvoidmain(String[]argv){PropertiesconnConfig=newProperties();connConfig.setProperty("user","db_user");connConfig.setProperty("password","db_user_password");connConfig.setProperty("useSsl","true");connConfig.setProperty("serverSslCert","/path/to/skysql_chain.pem");try(Connectionconn=DriverManager.getConnection("jdbc:mariadb://HOST:PORT",connConfig)){try(Statementstmt=conn.createStatement()){stmnt.execute("CREATE TABLE IF NOT EXISTS test.contacts ("+" id INT PRIMARY KEY AUTO_INCREMENT,"+" first_name VARCHAR(25),"+" last_name VARCHAR(25),"+" email VARCHAR(100)"+") ENGINE=InnoDB;");}}catch(Exceptione){e.printStackTrace();}}}
TRUNCATE TABLETRUNCATE TABLE is a DDL (Data Definition Language) operation that truncates a table. TRUNCATE drops the table, and creates a new table with the same definition, in effect deleting all data from an existing table.
The following example program truncates the test.contacts table created in the example setup.
Confirm the table was properly truncated using MariaDB Client to query the table's data using a SELECTSELECT statement. The statement should return an empty set, because the TRUNCATETRUNCATE statement deletes all data in the table.
Example output:
SELECT*fromtest.contacts;
Empty set (0.001 sec)
Connector/J 3.0
In MariaDB Connector/J 3.0, TLS is enabled for connections to SkySQL using the sslMode parameter.
Confirm the table was properly truncated using MariaDB Client to query the table's data using a SELECT statement. The statement should return an empty set, because the TRUNCATE statement deletes all data in the table.
Example output:
SELECT*fromtest.contacts;
Empty set (0.001 sec)
Connector/J 2.7
In MariaDB Connector/J 2.7 and before, TLS is enabled for connections to SkySQL using the useSsl parameter.
Confirm the table was properly truncated using MariaDB Client to query the table's data using a SELECT statement. The statement should return an empty set, because the TRUNCATE statement deletes all data in the table.