Legacy Knowledge Base
Published Sep. 10, 2025

Connect a single portlet to a different database other than the Liferay Database

Written By

Rishabh Agrawal

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

  • 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.properties with connection details and pool name.
  • Configure a bean in liferay-plugin-registry.xml to 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.
Did this article resolve your issue ?

Legacy Knowledge Base