Establish an external data source using JDBC
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
Legacy Article
You are viewing an article from our legacy "FastTrack"
publication program, made available for informational purposes. Articles
in this program were published without a requirement for independent
editing or verification and are provided"as is" without
guarantee.
Before using any information from this article, independently verify its
suitability for your situation and project.
Issue
- This article outlines how to set up a connection between Liferay and an external database using JDBC properties.
Environment
- Liferay DXP 7.3
- Liferay DXP 7.4
- MySQL database
Resolution
- There are two ways to connect Service Builder to an external database in Liferay: DataSourceProvider and Spring. In this case, the Spring dependency injector was used in the service builder module.
-
The steps that need to be performed are listed following:
1) Add jdbc.default for Liferay dxp DB and jdbc.ext for external DB
jdbc.default.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/dxp_db?characterEncoding=UTF-8&dontTrackOpenResources=true&holdResultsOpenOverStatementClose=true&serverTimezone=GMT&useFastDateParsing=false&useUnicode=true
jdbc.default.username=root
jdbc.default.password=root
jdbc.ext.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.ext.password=root
jdbc.ext.url=jdbc:mysql://localhost/external?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.ext.username=root
2) Create one database and a table
create database external character set utf8;
use external;
create table external_Sample (
name VARCHAR(75) null,
id_ bigint not null primary key
);
3)Restart the server.
4) Deploy the attached jars one by one (A sample plugin with three jars for API, Service, and web portlet is attached)
5) Drag the 'Hello from NewExternalDbSbWeb' portlet from the sample option on a page
6) Fill out the name
7) Check your external database for external_sample table entry.
Expected Behavior: The name is saved in the target external database table.
Did this article resolve your issue ?