If you want to use JDBC to connect to your virtual databases, you can use Teiid JDBC Driver to connect this virtual database from your java program. If you are using Maven for your java application development use the folowing as the maven dependency:
<dependency>
<groupId>org.teiid</groupId>
<artifactId>teiid</artifactId>
<classifier>jdbc</classifier>
<version>${version.teiid}</version>
</dependency>To connect to the database, use the following properties while establishing connection:
URL: jdbc:teiid:customer@mm://<service-host>:31000
JDBC Class: org.teiid.jdbc.TeiidDriver
JDBC Driver: teiid-13.0.2-jdbc.jar
or above
As this example does not use authentication, no credentials are needed. Also note that this connection only works from an application inside the OpenShift as there is no route/Ingress created for it. If Keycloak installed as security provider, then one must use the credentials to login.
|
Note
|
In this repository, see example called "simple-jdbc-client" which shows a JDBC example you can execute. |
|
Note
|
The transport layer of JDBC/PG is encrypted by default, but only over the secure ports. So, be cautious when creating external facing connections. |
JDBC is not exposed to outside applications by default (no route created). It is only suitable for applications in the cloud.
If you have an external application that is using JDBC or the Postgres protocol then a "LoadBalancer" service can be created such that any external application that is outside your cluster can be connected to this. To create "LoadBalancer", create your Custom Resource as below.
apiVersion: teiid.io/v1alpha1
kind: VirtualDatabase
metadata:
name: dv-customer
spec:
replicas: 1
expose: (1)
- LoadBalancer (2)
build:
source:
ddl: | (3)
CREATE DATABASE customer OPTIONS (ANNOTATION 'Customer VDB');
USE DATABASE customer;
...-
Request to expose a list of services like LoadBalancer, NodePort, Route (default), ExposeVia3scale
-
Expose a "LoadBalancer" service for this virtual database
To determine the ip/port of load balancer run:
$oc get svc <name>-ingress NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE <name>-external LoadBalancer 172.30.233.178 <pending> 31000:30430/TCP 22m
|
Note
|
The above external service may not be possible with public OpenShift instances as it requires opening a port. |
|
Note
|
When working with OpenShift 4.x/Code Ready Containers, if the EXTERNAL-IP value is set, your environment has an external load balancer that you can use for the ingress gateway. If the EXTERNAL-IP value is <none> (or perpetually <pending>), your environment does not provide an external load balancer for the ingress gateway. In this case, you can access the gateway using the service’s node port. For CRC you can see it by crc ip and in output of the above command you will see a Node level port. In above example, a pod’s 31000 port is assigned to 30430, you will need to connect to 30430 as JDBC port
|