Issue
- How to connect portlet to some other database which is separate from Liferay database using the conventional method like Connection and DriverManager of Java SQL classes and interface where the Database name with Username and Password should be provided.
Environment
- Liferay DXP 7.2
Resolution
One can use manual JDBC connections within the portlet code. This involves loading the appropriate JDBC driver and establishing a connection directly to the external database. However, this approach requires more manual code and might not be as secure or scalable as Service Builder.
For example:
-
Update
portal-ext.propertieswith connection details and pool name. -
Configure a bean in
liferay-plugin-registry.xmlto access the data source.
- It's important to note that while manually connecting to databases in Liferay 7.2 is possible through
liferay-plugin-registry.xml, it's generally not recommended due to security and maintenance concerns. Consider using Service Builder for a more secure and manageable approach.
-
Use the bean's
getConnection()method in your portlet code to acquire connections. - However, this is just a reference here, users can connect with their developer team and check this further as per their business requirements.
Additional Information
There are some additional points to consider:
- Security: Ensure proper credentials and connection pooling are used to avoid security vulnerabilities.
- Performance: Evaluate the impact of accessing additional databases on your Liferay portal's performance.
- Version compatibility: The specific steps and configuration files may differ depending on the Liferay version. Please note it is important to remember that connecting to different databases can add complexity to Liferay deployment. Carefully consider the needs and choose the approach that best suits the situation.