SlideShare a Scribd company logo
1 of 51
MariaDB java
Connector
Diego DUPIN
MariaDB Connector Engineer
MariaDB Corporation
PROGRAM
- Getting started
- Best practice
- Advanced topic
- ORM
MARIADB JAVA CONNECTOR
MariaDB is 100% java driver, initially fork from drizzle
JDBC 4.2 compliant
First release 2012
400K DL per month (maven stats)
JAVA CONNECTOR
Why not using MySQL connector ?
● MariaDB specific implementation
○ Bulk batch
○ Authentication (GSSAPI, ed25519 …)
● Performance : exemple on query “SELECT * FROM mysql.user”
Getting started
QUICK START - INSTALLATION
● 1.x java 7
● 2.x java 8+
maven <dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.4.0</version>
</dependency>
QUICK START - CREATE CONNECTION
auto-registration for “jdbc:mariadb”
try (Connection conn = DriverManager.getConnection("jdbc:mariadb://localhost/db?user=root")) {
System.out.println("Connection succeed");
} catch (SQLException sqle) {
System.out.println("Connection failed with err: " + sqle.getMessage());
}
DataSource datasource = new MariaDbDataSource("jdbc:mariadb://localhost/db?user=root");
try (Connection conn = datasource.getConnection()) {
System.out.println("Connection succeed");
} catch (SQLException sqle) {
System.out.println("Connection failed with err: " + sqle.getMessage());
}
QUICK START - CONNECTION STRING
jdbc:mariadb:[replication:|failover:|sequential:|aurora:]//<hostDescription>[,<hostDescription>...]/[database][
?<key1>=<value1>[&<key2>=<value2>]]
"jdbc:mariadb://localhost:3306/myDb?user=myUser&password=MyPwd&useSSL=true”
Essential options
● User
● Password
● connectTimeout
● localSocketAddress
… 87 options in total
QUICK START - INSERT
try (PreparedStatement prep = conn.prepareStatement("INSERT INTO myTable(firstName, lastName)
VALUES (?, ?)")) {
prep.setString(1, "john");
prep.setString(2, "Hancock");
prep.execute();
} catch (SQLException sqle) {
//handle error
}
QUICK START - SELECT
try (PreparedStatement prep = conn.prepareStatement("SELECT firstName, lastName
FROM myTable WHERE id = ?")) {
prep.setInt(1, 1000);
ResultSet rs = prep.executeQuery();
rs.next();
System.out.println(rs.getString(1) + " " + rs.getString(2));
} catch (SQLException sqle) {
//handle error
}
QUICK START
Statement stmt = conn.createStatement();
stmt.execute("INSERT INTO myTable(firstName, lastName) VALUES ('" + firstName +
"', '" + lastName + "')");
Not using ? parameters : SQL INJECTION
lastname = “‘) , (‘other name’, ‘other last name’); CREATE USER hack@’%’”
SSL
SSL - one way authentication
Server must be configured for SSL (yassl/openssl)
One-Way SSL Authentication .
Not reusing context
try (Connection con =
DriverManager.getConnection("jdbc:mariadb://localhost/myDb?user=myUser&password=MyPwd&useSSL=true”)) {
try (Statement stmt = con.createStatement()) {
stmt.execute("select 1");
}
}
CREATE USER 'myUser'@'%' IDENTIFIED BY 'MyPwd';
GRANT ALL ON db_name.* TO 'myUser'@'%' REQUIRE SSL;
SSL - mutual authentication
Server must be configured for SSL (yassl/openssl)
mutual SSL Authentication .
try (Connection con =
DriverManager.getConnection("jdbc:mariadb://localhost/myDb?user=myUser&password=MyPwd&useSSL=true&clientCertificateKe
yStoreUrl=/tmp/…”
)) {
try (Statement stmt = con.createStatement()) {
stmt.execute("select 1");
}
}
CREATE USER 'myUser'@'%' IDENTIFIED BY 'MyPwd';
GRANT ALL ON db_name.* TO 'myUser'@'%' REQUIRE X509;
SSL - some options
useSSL Force SSL/TLS on connection.
trustServerCertificate When using SSL/TLS, do not check server's certificate.
serverSslCert Permits providing server's certificate in DER form, or server's CA certificate.
keyStore File path of the keyStore file that contain client private key store and associate certificates
keyStorePassword Password for the client certificate keyStore
trustStore File path of the trustStore file (similar to java System property "javax.net.ssl.trustStore").
trustStorePassword Password for the trusted root certificate file (similar to java System property "javax.net.ssl.trustStorePassword").
enabledSslProtocolSuites Force TLS/SSL protocol to a specific set of TLS versions (comma separated list).
enabledSslCipherSuites Indicate permited ciphers
disableSslHostnameVerification checks the hostname against the server's identity as presented in the server's certificate
keyStoreType Indicate key store type (JKS/PKCS12). default is null, then using java default type.
trustStoreType Indicate trust store type (JKS/PKCS12). default is null, then using java default type.
Pooling
POOLING
Basically a database connection cache implementation
Connections are expensive. On local DB:
● 2.4ms for a basic connection
● 0.05ms for a simple query
Problem : correctness and reliability
POOLING
Lots of pools : apache dbcp2, HikariCP, c3p0
Best is HikariCP :
● Good default
● Widely used
● Very fast
● Show connection leaks
● Doesn’t always validate connection (500ms)
● Reliable :
○ Readonly, autocommit, isolation, schema, network timeout reset
○ rollback
● Pool handle connection creation in dedicated thread
POOLING
- Implementation to handle query pikes
Example with a pool that is configured to have a maximum of 50 connections. actual
connection number is 5.
With a basis of a connection creation taking 2.4ms, and query taking 0.05ms (example
on a local server).
Everything is quiet, and then ... Boom! ... 100 queries on the pool at once, wanting a
connection.
POOLING
POOLING
POOLING
● Good for failover recovery
Just
● configure “maxLifetime” option according to Server @@wait_timeout
● Don’t set “connectionTestQuery” option
● Avoid setting “minimumIdle” option
● If always disabling autocommit (hibernate):
○ autoCommit option to false
○ "jdbc:mariadb://localhost/db?user=user&sessionVariables=autocommit=0";
POOLING
Connection pools SIZING error
Example 10 000 user simultaneously, 20 000 transaction per second.
What value to connectionLimit (max connection number in pool) ?
100 ? 500 ? 1000 ?
Streaming
Streaming
Goal : Avoid loading all in memory
● Streaming resultset -> avoiding loading large resultset totally into memory
● Streaming sent -> sending buffer by chunk
Streaming resultset
Limitations :
● Server net_write_timeout.
○ For a command: SET STATEMENT net_write_timeout=10000 FOR XXX
○ For a connection: ”&sessionVariables=net_write_timeout=31536000”
stmt.setFetchSize(100);
ResultSet rs = stmt.executeQuery("SELECT charValue FROM
testBatchString");
int counter = 0;
while (rs.next()) {
System.out.println(rs.getString(1));
}
Streaming - sending
try (FileInputStream fis = new FileInputStream(tmpFile)) {
try (PreparedStatement ps = sharedConnection.prepareStatement("insert into bigblob
values(?)")) {
ps.setCharacterStream(1, new InputStreamReader(fis, StandardCharsets.UTF_8));
ps.executeUpdate();
}
}
Limitations :
● Server net_read_timeout
● max_allowed_packet
BULK
BULK
● One after One
● Pipelining (default)
● Rewrite (rewriteBatchedStatements)
● Bulk insert (useBulkStmts)
int[] executeBatch() throws SQLException
MULTI-SERVER
MULTI-HOST
load balancing and high availability
jdbc:mariadb:[replication:|failover:|sequential:]//<hostDescription>[,<hostDescription>...]/[database][?<key1>=<
value1>[&<key2>=<value2>]]
Sequential multi-master with failover support, always using in sequence until fails
Failover multi-master with failover support
Replication multi-master + multi-slave with failover support
MULTI-HOST
client
Master
Slave B
Slave A
"jdbc:mariadb:replication://master,slaveA,slaveB/db"
Pools with 4
connections
MULTI-HOST
client
Master
Slave B
Slave A
"jdbc:mariadb:replication://master,slaveA,slaveB/db"
Pools with 4
connections
MULTI-HOST
Using standard JDBC
try {Connection conn =
DriverManager.getConnection("jdbc:mysql:replication://master1,slave1/db?user=root")) {
Statement stmt = conn.createStatement();
stmt.execute("SELECT 1"); // will execute query on the underlying master1 connection
conn.setReadOnly(true);
stmt.execute("SELECT 1"); // will execute query on the underlying slave1 connection
}
MULTI-HOST
Using Hibernate
Using Spring data jpa : automatic findxxx() automatically setReadOnly(true)
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void createUser(EntityManager em) {
User user = new User("Jean claude", "Van Damme");
em.persist(user);
}
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public User findUser(EntityManager em, Integer id) {
return em.find(User.class, id);
}
ORM
SPRING DATA JPA
Spring data JPA is the actual reference in java.
Need configuration for optimisation. Example with :
repository.save(new User("Jack", "Bauer"));
repository.save(new User("Chloe", "O'Brian"));
List<User> users = new ArrayList();
users.add(new User("Kim", "Bauer"));
users.add(new User("David", "Palmer"));
users.add(new User("Michelle", "Dessler"));
Iterable<User> savedUsers = repository.saveAll(users);
savedUsers.forEach(user -> {
System.out.println(user);
});
public class User {
public User(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String lastName;
private String firstName;
}
SPRING DATA JPA
set autocommit=0
set autocommit=0
select next_val as id_val from hibernate_sequence for update
update hibernate_sequence set next_val= ? where next_val=?, parameters [2,1]
COMMIT
set autocommit=1
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1]
COMMIT
set autocommit=1
set autocommit=0
set autocommit=0
select next_val as id_val from hibernate_sequence for update
update hibernate_sequence set next_val= ? where next_val=?, parameters [3,2]
COMMIT
set autocommit=1
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2]
COMMIT
set autocommit=1
set autocommit=0
set autocommit=0
select next_val as id_val from hibernate_sequence for update
update hibernate_sequence set next_val= ? where next_val=?, parameters [4,3]
COMMIT
set autocommit=1
set autocommit=0
select next_val as id_val from hibernate_sequence for update
SPRING DATA JPA
With HikariCP configured with autocommit : false and adding “autocommit=0” to connection string
(dialect MySQL5Dialect)
select next_val as id_val from hibernate_sequence for update
update hibernate_sequence set next_val= ? where next_val=?, parameters [2,1]
COMMIT
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1]
COMMIT
select next_val as id_val from hibernate_sequence for update
update hibernate_sequence set next_val= ? where next_val=?, parameters [3,2]
COMMIT
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2]
COMMIT
select next_val as id_val from hibernate_sequence for update
update hibernate_sequence set next_val= ? where next_val=?, parameters [4,3]
COMMIT
select next_val as id_val from hibernate_sequence for update
update hibernate_sequence set next_val= ? where next_val=?, parameters [5,4]
COMMIT
select next_val as id_val from hibernate_sequence for update
update hibernate_sequence set next_val= ? where next_val=?, parameters [6,5]
COMMIT
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3]
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Palmer','David',4]
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Dessler','Michelle',5]
COMMIT
SPRING DATA JPA
With HikariCP configured with autocommit : false and adding “autocommit=0” to connection string
(dialect MariaDB103Dialect)
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1]
COMMIT
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2]
COMMIT
select nextval(hibernate_sequence)
select nextval(hibernate_sequence)
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3]
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Palmer','David',4]
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Dessler','Michelle',5]
COMMIT
SPRING DATA JPA
Changing default strategy auto to native :
public class User {
public User(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
@GenericGenerator(name = "native", strategy = "native")
private Integer id;
private String lastName;
private String firstName;
}
SPRING DATA JPA
With HikariCP configured with autocommit : false and adding “autocommit=0” to connection string
(dialect MariaDB103Dialect + strategy native)
insert into User (firstName, lastName) values (?, ?), parameters ['Bauer','Jack']
COMMIT
insert into User (firstName, lastName) values (?, ?), parameters ['O'Brian','Chloe']
COMMIT
insert into User (firstName, lastName) values (?, ?), parameters ['Bauer','Kim']
insert into User (firstName, lastName) values (?, ?), parameters ['Palmer','David']
insert into User (firstName, lastName) values (?, ?), parameters ['Dessler','Michelle']
COMMIT
SPRING DATA JPA
With HikariCP configured with autocommit : false and adding “autocommit=0” to connection string
(dialect MariaDB103Dialect)
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1]
COMMIT
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2]
COMMIT
select nextval(hibernate_sequence)
select nextval(hibernate_sequence)
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3]
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Palmer','David',4]
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Dessler','Michelle',5]
COMMIT
SPRING DATA JPA
With HikariCP configured with autocommit : false and adding
“&sessionVariables=autocommit=0&useBulkStmts&rewriteBatchedStatements” to connection string
(dialect MariaDB103Dialect)
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1]
COMMIT
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2]
COMMIT
select nextval(hibernate_sequence)
select nextval(hibernate_sequence)
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3]
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Palmer','David',4]
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Dessler','Michelle',5]
COMMIT
SPRING DATA JPA
using sequence in pool:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@GenericGenerator(
name = "sequenceGenerator",
strategy = "enhanced-sequence",
parameters = {
@org.hibernate.annotations.Parameter(
name = "optimizer",
value = "pooled"
),
@org.hibernate.annotations.Parameter(
name = "initial_value",
value = "1"
),
@org.hibernate.annotations.Parameter(
name = "increment_size",
value = "5"
)
}
)
private Integer id;
SPRING DATA JPA
With HikariCP configured with autocommit : false and adding
“&sessionVariables=autocommit=0&useBulkStmts&rewriteBatchedStatements” to connection string
(dialect MariaDB103Dialect)
select nextval(hibernate_sequence)
select nextval(hibernate_sequence)
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1]
COMMIT
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2]
COMMIT
insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3],['Palmer','David',4],['Dessler','Michelle',5]
COMMIT
tricks
AVOID TCP-IP layer for local connection
Connection options for local server
- UNIX domain (option “localSocket”)
- Windows named pipe (option “pipe”)
const mariadb = require('mariadb');
mariadb.createConnection({ socketPath: '/tmp/mysql.sock', user: 'root' })
.then(conn => { ... })
.catch(err => { ... });
METADATA
● Select query = row datas + metadata
Metadata = datatype, format, and lots of additional infos: schema, table name,
table alias, column name, column alias, … Not always needed
ResultSet rs = state.statement.executeQuery("select * from
mysql.user LIMIT 1");
rs.next();
rs.getString(1);
rs.getString(2);
…
vs
s.getString("Host");
rs.getString("User");
...
What next ?
Performance improvement
Pool + Failover improvement
ADBA / R2DBC
THANK YOU!

More Related Content

What's hot

Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseChristian Melchior
 
Ordonnancement exercices
Ordonnancement exercicesOrdonnancement exercices
Ordonnancement exercicesSelman Dridi
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Building an Activity Feed with Cassandra
Building an Activity Feed with CassandraBuilding an Activity Feed with Cassandra
Building an Activity Feed with CassandraMark Dunphy
 
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기NAVER D2
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js선협 이
 
5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment 5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment pcnmtutorials
 
Exercice 1 java Héritage
Exercice 1 java HéritageExercice 1 java Héritage
Exercice 1 java HéritageNadaBenLatifa
 
Chapitre 2 problème de plus court chemin
Chapitre 2 problème de plus court cheminChapitre 2 problème de plus court chemin
Chapitre 2 problème de plus court cheminSana Aroussi
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)Stephen Chin
 

What's hot (20)

Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Ordonnancement exercices
Ordonnancement exercicesOrdonnancement exercices
Ordonnancement exercices
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Building an Activity Feed with Cassandra
Building an Activity Feed with CassandraBuilding an Activity Feed with Cassandra
Building an Activity Feed with Cassandra
 
Cours design pattern m youssfi partie 5 adapter
Cours design pattern m youssfi partie 5 adapterCours design pattern m youssfi partie 5 adapter
Cours design pattern m youssfi partie 5 adapter
 
Alcatel vm
Alcatel vmAlcatel vm
Alcatel vm
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Fluent Bit: Log Forwarding at Scale
Fluent Bit: Log Forwarding at ScaleFluent Bit: Log Forwarding at Scale
Fluent Bit: Log Forwarding at Scale
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
SQL-ORACLE.pptx
SQL-ORACLE.pptxSQL-ORACLE.pptx
SQL-ORACLE.pptx
 
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기
 
Lecture09 recursion
Lecture09 recursionLecture09 recursion
Lecture09 recursion
 
Server side rendering review
Server side rendering reviewServer side rendering review
Server side rendering review
 
Deep dive into Vue.js
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js
 
5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment 5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment
 
Récursivité
RécursivitéRécursivité
Récursivité
 
Exercice 1 java Héritage
Exercice 1 java HéritageExercice 1 java Héritage
Exercice 1 java Héritage
 
Chapitre 2 problème de plus court chemin
Chapitre 2 problème de plus court cheminChapitre 2 problème de plus court chemin
Chapitre 2 problème de plus court chemin
 
Twig tips and tricks
Twig tips and tricksTwig tips and tricks
Twig tips and tricks
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
 

Similar to Using advanced options in MariaDB Connector/J

20151010 my sq-landjavav2a
20151010 my sq-landjavav2a20151010 my sq-landjavav2a
20151010 my sq-landjavav2aIvan Ma
 
Intro ProxySQL
Intro ProxySQLIntro ProxySQL
Intro ProxySQLI Goo Lee
 
Building better Node.js applications on MariaDB
Building better Node.js applications on MariaDBBuilding better Node.js applications on MariaDB
Building better Node.js applications on MariaDBMariaDB plc
 
Ch10.애플리케이션 서버의 병목_발견_방법
Ch10.애플리케이션 서버의 병목_발견_방법Ch10.애플리케이션 서버의 병목_발견_방법
Ch10.애플리케이션 서버의 병목_발견_방법Minchul Jung
 
Plmce2015 java 101 - david bennett
Plmce2015   java 101 - david bennettPlmce2015   java 101 - david bennett
Plmce2015 java 101 - david bennettDavid Bennett
 
34 using mysql with java
34 using mysql with java34 using mysql with java
34 using mysql with java果 果
 
Amazon RDS for MySQL: Best Practices and Migration
Amazon RDS for MySQL: Best Practices and MigrationAmazon RDS for MySQL: Best Practices and Migration
Amazon RDS for MySQL: Best Practices and MigrationAmazon Web Services
 
Amazon RDS for MySQL: Best Practices and Migration
Amazon RDS for MySQL: Best Practices and MigrationAmazon RDS for MySQL: Best Practices and Migration
Amazon RDS for MySQL: Best Practices and MigrationAmazon Web Services
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...Timofey Turenko
 

Similar to Using advanced options in MariaDB Connector/J (20)

20151010 my sq-landjavav2a
20151010 my sq-landjavav2a20151010 my sq-landjavav2a
20151010 my sq-landjavav2a
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Jdbc
JdbcJdbc
Jdbc
 
Java JDBC
Java JDBCJava JDBC
Java JDBC
 
Intro ProxySQL
Intro ProxySQLIntro ProxySQL
Intro ProxySQL
 
J boss
J bossJ boss
J boss
 
22jdbc
22jdbc22jdbc
22jdbc
 
Building better Node.js applications on MariaDB
Building better Node.js applications on MariaDBBuilding better Node.js applications on MariaDB
Building better Node.js applications on MariaDB
 
Ch10.애플리케이션 서버의 병목_발견_방법
Ch10.애플리케이션 서버의 병목_발견_방법Ch10.애플리케이션 서버의 병목_발견_방법
Ch10.애플리케이션 서버의 병목_발견_방법
 
Plmce2015 java 101 - david bennett
Plmce2015   java 101 - david bennettPlmce2015   java 101 - david bennett
Plmce2015 java 101 - david bennett
 
Mysql S&M
Mysql S&MMysql S&M
Mysql S&M
 
34 using mysql with java
34 using mysql with java34 using mysql with java
34 using mysql with java
 
Jdbc
JdbcJdbc
Jdbc
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
DynamoDB for PHP sessions
DynamoDB for PHP sessionsDynamoDB for PHP sessions
DynamoDB for PHP sessions
 
Amazon RDS for MySQL: Best Practices and Migration
Amazon RDS for MySQL: Best Practices and MigrationAmazon RDS for MySQL: Best Practices and Migration
Amazon RDS for MySQL: Best Practices and Migration
 
Amazon RDS for MySQL: Best Practices and Migration
Amazon RDS for MySQL: Best Practices and MigrationAmazon RDS for MySQL: Best Practices and Migration
Amazon RDS for MySQL: Best Practices and Migration
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
 
10 J D B C
10  J D B C10  J D B C
10 J D B C
 

More from MariaDB plc

MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.xMariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.xMariaDB plc
 
MariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - NewpharmaMariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - NewpharmaMariaDB plc
 
MariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - CloudMariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - CloudMariaDB plc
 
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB EnterpriseMariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB EnterpriseMariaDB plc
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB plc
 
MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale MariaDB plc
 
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentationMariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentationMariaDB plc
 
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentationMariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentationMariaDB plc
 
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server MariaDB plc
 
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-BackupMariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-BackupMariaDB plc
 
Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023MariaDB plc
 
Hochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDBHochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDBMariaDB plc
 
Die Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise ServerDie Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise ServerMariaDB plc
 
Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®MariaDB plc
 
Introducing workload analysis
Introducing workload analysisIntroducing workload analysis
Introducing workload analysisMariaDB plc
 
Under the hood: SkySQL monitoring
Under the hood: SkySQL monitoringUnder the hood: SkySQL monitoring
Under the hood: SkySQL monitoringMariaDB plc
 
Introducing the R2DBC async Java connector
Introducing the R2DBC async Java connectorIntroducing the R2DBC async Java connector
Introducing the R2DBC async Java connectorMariaDB plc
 
MariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB plc
 
Faster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDBFaster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDBMariaDB plc
 
The architecture of SkySQL
The architecture of SkySQLThe architecture of SkySQL
The architecture of SkySQLMariaDB plc
 

More from MariaDB plc (20)

MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.xMariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.x
 
MariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - NewpharmaMariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - Newpharma
 
MariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - CloudMariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - Cloud
 
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB EnterpriseMariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB Enterprise
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance Optimization
 
MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale
 
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentationMariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentation
 
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentationMariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentation
 
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
 
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-BackupMariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
 
Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023
 
Hochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDBHochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDB
 
Die Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise ServerDie Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise Server
 
Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®
 
Introducing workload analysis
Introducing workload analysisIntroducing workload analysis
Introducing workload analysis
 
Under the hood: SkySQL monitoring
Under the hood: SkySQL monitoringUnder the hood: SkySQL monitoring
Under the hood: SkySQL monitoring
 
Introducing the R2DBC async Java connector
Introducing the R2DBC async Java connectorIntroducing the R2DBC async Java connector
Introducing the R2DBC async Java connector
 
MariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introduction
 
Faster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDBFaster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDB
 
The architecture of SkySQL
The architecture of SkySQLThe architecture of SkySQL
The architecture of SkySQL
 

Recently uploaded

Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 

Recently uploaded (20)

Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 

Using advanced options in MariaDB Connector/J

  • 1. MariaDB java Connector Diego DUPIN MariaDB Connector Engineer MariaDB Corporation
  • 2. PROGRAM - Getting started - Best practice - Advanced topic - ORM
  • 3. MARIADB JAVA CONNECTOR MariaDB is 100% java driver, initially fork from drizzle JDBC 4.2 compliant First release 2012 400K DL per month (maven stats)
  • 4. JAVA CONNECTOR Why not using MySQL connector ? ● MariaDB specific implementation ○ Bulk batch ○ Authentication (GSSAPI, ed25519 …) ● Performance : exemple on query “SELECT * FROM mysql.user”
  • 6. QUICK START - INSTALLATION ● 1.x java 7 ● 2.x java 8+ maven <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version>2.4.0</version> </dependency>
  • 7. QUICK START - CREATE CONNECTION auto-registration for “jdbc:mariadb” try (Connection conn = DriverManager.getConnection("jdbc:mariadb://localhost/db?user=root")) { System.out.println("Connection succeed"); } catch (SQLException sqle) { System.out.println("Connection failed with err: " + sqle.getMessage()); } DataSource datasource = new MariaDbDataSource("jdbc:mariadb://localhost/db?user=root"); try (Connection conn = datasource.getConnection()) { System.out.println("Connection succeed"); } catch (SQLException sqle) { System.out.println("Connection failed with err: " + sqle.getMessage()); }
  • 8. QUICK START - CONNECTION STRING jdbc:mariadb:[replication:|failover:|sequential:|aurora:]//<hostDescription>[,<hostDescription>...]/[database][ ?<key1>=<value1>[&<key2>=<value2>]] "jdbc:mariadb://localhost:3306/myDb?user=myUser&password=MyPwd&useSSL=true” Essential options ● User ● Password ● connectTimeout ● localSocketAddress … 87 options in total
  • 9. QUICK START - INSERT try (PreparedStatement prep = conn.prepareStatement("INSERT INTO myTable(firstName, lastName) VALUES (?, ?)")) { prep.setString(1, "john"); prep.setString(2, "Hancock"); prep.execute(); } catch (SQLException sqle) { //handle error }
  • 10. QUICK START - SELECT try (PreparedStatement prep = conn.prepareStatement("SELECT firstName, lastName FROM myTable WHERE id = ?")) { prep.setInt(1, 1000); ResultSet rs = prep.executeQuery(); rs.next(); System.out.println(rs.getString(1) + " " + rs.getString(2)); } catch (SQLException sqle) { //handle error }
  • 11. QUICK START Statement stmt = conn.createStatement(); stmt.execute("INSERT INTO myTable(firstName, lastName) VALUES ('" + firstName + "', '" + lastName + "')"); Not using ? parameters : SQL INJECTION lastname = “‘) , (‘other name’, ‘other last name’); CREATE USER hack@’%’”
  • 12. SSL
  • 13. SSL - one way authentication Server must be configured for SSL (yassl/openssl) One-Way SSL Authentication . Not reusing context try (Connection con = DriverManager.getConnection("jdbc:mariadb://localhost/myDb?user=myUser&password=MyPwd&useSSL=true”)) { try (Statement stmt = con.createStatement()) { stmt.execute("select 1"); } } CREATE USER 'myUser'@'%' IDENTIFIED BY 'MyPwd'; GRANT ALL ON db_name.* TO 'myUser'@'%' REQUIRE SSL;
  • 14. SSL - mutual authentication Server must be configured for SSL (yassl/openssl) mutual SSL Authentication . try (Connection con = DriverManager.getConnection("jdbc:mariadb://localhost/myDb?user=myUser&password=MyPwd&useSSL=true&clientCertificateKe yStoreUrl=/tmp/…” )) { try (Statement stmt = con.createStatement()) { stmt.execute("select 1"); } } CREATE USER 'myUser'@'%' IDENTIFIED BY 'MyPwd'; GRANT ALL ON db_name.* TO 'myUser'@'%' REQUIRE X509;
  • 15. SSL - some options useSSL Force SSL/TLS on connection. trustServerCertificate When using SSL/TLS, do not check server's certificate. serverSslCert Permits providing server's certificate in DER form, or server's CA certificate. keyStore File path of the keyStore file that contain client private key store and associate certificates keyStorePassword Password for the client certificate keyStore trustStore File path of the trustStore file (similar to java System property "javax.net.ssl.trustStore"). trustStorePassword Password for the trusted root certificate file (similar to java System property "javax.net.ssl.trustStorePassword"). enabledSslProtocolSuites Force TLS/SSL protocol to a specific set of TLS versions (comma separated list). enabledSslCipherSuites Indicate permited ciphers disableSslHostnameVerification checks the hostname against the server's identity as presented in the server's certificate keyStoreType Indicate key store type (JKS/PKCS12). default is null, then using java default type. trustStoreType Indicate trust store type (JKS/PKCS12). default is null, then using java default type.
  • 17. POOLING Basically a database connection cache implementation Connections are expensive. On local DB: ● 2.4ms for a basic connection ● 0.05ms for a simple query Problem : correctness and reliability
  • 18. POOLING Lots of pools : apache dbcp2, HikariCP, c3p0 Best is HikariCP : ● Good default ● Widely used ● Very fast ● Show connection leaks ● Doesn’t always validate connection (500ms) ● Reliable : ○ Readonly, autocommit, isolation, schema, network timeout reset ○ rollback ● Pool handle connection creation in dedicated thread
  • 19. POOLING - Implementation to handle query pikes Example with a pool that is configured to have a maximum of 50 connections. actual connection number is 5. With a basis of a connection creation taking 2.4ms, and query taking 0.05ms (example on a local server). Everything is quiet, and then ... Boom! ... 100 queries on the pool at once, wanting a connection.
  • 22. POOLING ● Good for failover recovery Just ● configure “maxLifetime” option according to Server @@wait_timeout ● Don’t set “connectionTestQuery” option ● Avoid setting “minimumIdle” option ● If always disabling autocommit (hibernate): ○ autoCommit option to false ○ "jdbc:mariadb://localhost/db?user=user&sessionVariables=autocommit=0";
  • 23. POOLING Connection pools SIZING error Example 10 000 user simultaneously, 20 000 transaction per second. What value to connectionLimit (max connection number in pool) ? 100 ? 500 ? 1000 ?
  • 25. Streaming Goal : Avoid loading all in memory ● Streaming resultset -> avoiding loading large resultset totally into memory ● Streaming sent -> sending buffer by chunk
  • 26. Streaming resultset Limitations : ● Server net_write_timeout. ○ For a command: SET STATEMENT net_write_timeout=10000 FOR XXX ○ For a connection: ”&sessionVariables=net_write_timeout=31536000” stmt.setFetchSize(100); ResultSet rs = stmt.executeQuery("SELECT charValue FROM testBatchString"); int counter = 0; while (rs.next()) { System.out.println(rs.getString(1)); }
  • 27. Streaming - sending try (FileInputStream fis = new FileInputStream(tmpFile)) { try (PreparedStatement ps = sharedConnection.prepareStatement("insert into bigblob values(?)")) { ps.setCharacterStream(1, new InputStreamReader(fis, StandardCharsets.UTF_8)); ps.executeUpdate(); } } Limitations : ● Server net_read_timeout ● max_allowed_packet
  • 28. BULK
  • 29. BULK ● One after One ● Pipelining (default) ● Rewrite (rewriteBatchedStatements) ● Bulk insert (useBulkStmts) int[] executeBatch() throws SQLException
  • 31. MULTI-HOST load balancing and high availability jdbc:mariadb:[replication:|failover:|sequential:]//<hostDescription>[,<hostDescription>...]/[database][?<key1>=< value1>[&<key2>=<value2>]] Sequential multi-master with failover support, always using in sequence until fails Failover multi-master with failover support Replication multi-master + multi-slave with failover support
  • 34. MULTI-HOST Using standard JDBC try {Connection conn = DriverManager.getConnection("jdbc:mysql:replication://master1,slave1/db?user=root")) { Statement stmt = conn.createStatement(); stmt.execute("SELECT 1"); // will execute query on the underlying master1 connection conn.setReadOnly(true); stmt.execute("SELECT 1"); // will execute query on the underlying slave1 connection }
  • 35. MULTI-HOST Using Hibernate Using Spring data jpa : automatic findxxx() automatically setReadOnly(true) @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public void createUser(EntityManager em) { User user = new User("Jean claude", "Van Damme"); em.persist(user); } @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public User findUser(EntityManager em, Integer id) { return em.find(User.class, id); }
  • 36. ORM
  • 37. SPRING DATA JPA Spring data JPA is the actual reference in java. Need configuration for optimisation. Example with : repository.save(new User("Jack", "Bauer")); repository.save(new User("Chloe", "O'Brian")); List<User> users = new ArrayList(); users.add(new User("Kim", "Bauer")); users.add(new User("David", "Palmer")); users.add(new User("Michelle", "Dessler")); Iterable<User> savedUsers = repository.saveAll(users); savedUsers.forEach(user -> { System.out.println(user); }); public class User { public User(String lastName, String firstName) { this.lastName = lastName; this.firstName = firstName; } @Id @GeneratedValue(strategy=GenerationType.AUTO) private Integer id; private String lastName; private String firstName; }
  • 38. SPRING DATA JPA set autocommit=0 set autocommit=0 select next_val as id_val from hibernate_sequence for update update hibernate_sequence set next_val= ? where next_val=?, parameters [2,1] COMMIT set autocommit=1 insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1] COMMIT set autocommit=1 set autocommit=0 set autocommit=0 select next_val as id_val from hibernate_sequence for update update hibernate_sequence set next_val= ? where next_val=?, parameters [3,2] COMMIT set autocommit=1 insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2] COMMIT set autocommit=1 set autocommit=0 set autocommit=0 select next_val as id_val from hibernate_sequence for update update hibernate_sequence set next_val= ? where next_val=?, parameters [4,3] COMMIT set autocommit=1 set autocommit=0 select next_val as id_val from hibernate_sequence for update
  • 39. SPRING DATA JPA With HikariCP configured with autocommit : false and adding “autocommit=0” to connection string (dialect MySQL5Dialect) select next_val as id_val from hibernate_sequence for update update hibernate_sequence set next_val= ? where next_val=?, parameters [2,1] COMMIT insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1] COMMIT select next_val as id_val from hibernate_sequence for update update hibernate_sequence set next_val= ? where next_val=?, parameters [3,2] COMMIT insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2] COMMIT select next_val as id_val from hibernate_sequence for update update hibernate_sequence set next_val= ? where next_val=?, parameters [4,3] COMMIT select next_val as id_val from hibernate_sequence for update update hibernate_sequence set next_val= ? where next_val=?, parameters [5,4] COMMIT select next_val as id_val from hibernate_sequence for update update hibernate_sequence set next_val= ? where next_val=?, parameters [6,5] COMMIT insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3] insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Palmer','David',4] insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Dessler','Michelle',5] COMMIT
  • 40. SPRING DATA JPA With HikariCP configured with autocommit : false and adding “autocommit=0” to connection string (dialect MariaDB103Dialect) select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1] COMMIT select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2] COMMIT select nextval(hibernate_sequence) select nextval(hibernate_sequence) select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3] insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Palmer','David',4] insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Dessler','Michelle',5] COMMIT
  • 41. SPRING DATA JPA Changing default strategy auto to native : public class User { public User(String lastName, String firstName) { this.lastName = lastName; this.firstName = firstName; } @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "native") @GenericGenerator(name = "native", strategy = "native") private Integer id; private String lastName; private String firstName; }
  • 42. SPRING DATA JPA With HikariCP configured with autocommit : false and adding “autocommit=0” to connection string (dialect MariaDB103Dialect + strategy native) insert into User (firstName, lastName) values (?, ?), parameters ['Bauer','Jack'] COMMIT insert into User (firstName, lastName) values (?, ?), parameters ['O'Brian','Chloe'] COMMIT insert into User (firstName, lastName) values (?, ?), parameters ['Bauer','Kim'] insert into User (firstName, lastName) values (?, ?), parameters ['Palmer','David'] insert into User (firstName, lastName) values (?, ?), parameters ['Dessler','Michelle'] COMMIT
  • 43. SPRING DATA JPA With HikariCP configured with autocommit : false and adding “autocommit=0” to connection string (dialect MariaDB103Dialect) select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1] COMMIT select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2] COMMIT select nextval(hibernate_sequence) select nextval(hibernate_sequence) select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3] insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Palmer','David',4] insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Dessler','Michelle',5] COMMIT
  • 44. SPRING DATA JPA With HikariCP configured with autocommit : false and adding “&sessionVariables=autocommit=0&useBulkStmts&rewriteBatchedStatements” to connection string (dialect MariaDB103Dialect) select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1] COMMIT select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2] COMMIT select nextval(hibernate_sequence) select nextval(hibernate_sequence) select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3] insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Palmer','David',4] insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Dessler','Michelle',5] COMMIT
  • 45. SPRING DATA JPA using sequence in pool: @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") @GenericGenerator( name = "sequenceGenerator", strategy = "enhanced-sequence", parameters = { @org.hibernate.annotations.Parameter( name = "optimizer", value = "pooled" ), @org.hibernate.annotations.Parameter( name = "initial_value", value = "1" ), @org.hibernate.annotations.Parameter( name = "increment_size", value = "5" ) } ) private Integer id;
  • 46. SPRING DATA JPA With HikariCP configured with autocommit : false and adding “&sessionVariables=autocommit=0&useBulkStmts&rewriteBatchedStatements” to connection string (dialect MariaDB103Dialect) select nextval(hibernate_sequence) select nextval(hibernate_sequence) insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Jack',1] COMMIT insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['O'Brian','Chloe',2] COMMIT insert into User (firstName, lastName, id) values (?, ?, ?), parameters ['Bauer','Kim',3],['Palmer','David',4],['Dessler','Michelle',5] COMMIT
  • 48. AVOID TCP-IP layer for local connection Connection options for local server - UNIX domain (option “localSocket”) - Windows named pipe (option “pipe”) const mariadb = require('mariadb'); mariadb.createConnection({ socketPath: '/tmp/mysql.sock', user: 'root' }) .then(conn => { ... }) .catch(err => { ... });
  • 49. METADATA ● Select query = row datas + metadata Metadata = datatype, format, and lots of additional infos: schema, table name, table alias, column name, column alias, … Not always needed ResultSet rs = state.statement.executeQuery("select * from mysql.user LIMIT 1"); rs.next(); rs.getString(1); rs.getString(2); … vs s.getString("Host"); rs.getString("User"); ...
  • 50. What next ? Performance improvement Pool + Failover improvement ADBA / R2DBC