Mapping to JDBC
To query external JDBC data stores, you can create a mapping to them with the JDBC connector.
The JDBC connector allows you to connect to any database that supports the JDBC interface.
The JDBC connector is included in the full and slim distributions of Hazelcast.
Before you can create a mapping to an external data store, you must have the following:
A JDBC driver that’s compatible with your data store. This driver must be on the classpath of your cluster members:
The full distribution of Hazelcast comes with a JDBC driver for MySQL, PostgreSQL, and H2 data stores, but currently Hazelcast Enterprise does not include a JDBC driver for MySQL.
The slim distribution of Hazelcast does not come with a JDBC driver.
A data store connection that’s configured on all cluster members.
Create the database that you’ll use as your external data store.
The following example creates a mapping to a MySQL database.
In the MySQL database, create a
CREATE TABLE people (id INT PRIMARY KEY, name VARCHAR(100))
CREATE MAPPING statement to tell the JDBC connector the name of your data store configuration.
external-data-store: mysql-database: (1) class-name: com.hazelcast.datastore.JdbcDataStoreFactory properties: jdbcUrl: jdbc:mysql://dummy:3306 username: xyz password: xyz shared: true
|1||Configuration details for a MySQL database.|
Create the mapping.
CREATE MAPPING people TYPE JDBC (1) OPTIONS ( 'externalDataStoreRef'='mysql-database' (2) )
|1||The name of the connector.|
|2||The name of the external data store configuration on your members.|