Liferay 6 Development Learning (26): Database Connectivity related issues

Source: Internet
Author: User
Tags connection pooling postgresql

How to change database in Liferay?

Often encountered someone asked Liferay how to change the database, how to modify the database connection. The first time we start Liferay, there will be a configuration wizard where we can select the database and configure the database connection information. What if I now select the PostgreSQL database in the wizard, but what do I want to change to Oracle later?

After you finish the Configuration Wizard, a file is generated under the Liferay directory. We open this file and can see the following database connection information in it.

jdbc.default.driverclassname=org.postgresql.driverjdbc.default.url=jdbc:postgresql://localhost:5432/ Liferay62jdbc.default.username=postgresjdbc.default.password=postgres

These lines we know is the database connection information, configured for the JDBC Connection driver name, JDBC connection string, database user name, database password and so on a few information, we need to replace the database, here to modify the database as we want.

Why do you see some tutorials or articles that are modified in the Root/web-inf/classes/ file? Please refer to "Liferay in Common configuration parameters" this blog in front of a small part, in these two files are can be modified, see oneself like.

What does the Liferay do with database connections?

The liferay underlying is the use of database operations in Hibernate,liferay through Hibernate. The default is to use the C3PO connection pool. We can also make connection pooling adjustments by,, or other *.properties files.


The default configuration, as above, can be adjusted to the connection pool we need. There are also many configuration parameters about the connection pool (can be found in the source file)

Jdbc.default.acquireincrement=5 jdbc.default.acquireretryattempts=3 jdbc.default.acquireretrydelay=1000 Jdbc.default.connectioncustomizerclassname=com.liferay.portal.dao.jdbc.pool.c3p0.portalconnectioncustomizer jdbc.default.idleconnectiontestperiod=60 jdbc.default.maxidletime=3600 jdbc.default.maxpoolsize=100 jdbc.default.minpoolsize=10 jdbc.default.numhelperthreads=10 #jdbc. default.transactionisolation=1
#jdbc. default.defaulttransactionisolation=read_uncommitted jdbc.default.maxactive=100 jdbc.default.minIdle=10 jdbc.default.removeabandonedtimeout=3600
Jdbc.default.jdbcinterceptors=org.apache.tomcat.jdbc.pool.interceptor.connectionstate jdbc.default.jmxEnabled= True Jdbc.default.fairqueue=true jdbc.default.timebetweenevictionrunsmillis=30000 Jdbc.default.useEquals=false

We can adjust and optimize the above parameters according to our own actual situation. Liferay the underlying configuration of the hibernate,hibernate is also available, for example, we want to print out the executed SQL statement in the console. You only need to configure the following parameters:


The default is False. For more Hibernate default configuration information, you can search for hibernate within Found.

Data sources that let Liferay use the middleware

Sometimes we don't want to use a JDBC connection pool to manage our database connections, and we want to use middleware data sources, such as Tomcat's data sources, WebLogic data sources. At this point we only need to add the following configuration in or

So we're going to let Liferay go to the middleware data source to find the database connection. Of course, the Jndi name of the data source must be configured as Jdbc/liferaypool, and the configuration of those JDBC connections in front of you is not required. You can delete it at this time.

What databases does Liferay support?

One might think that Liferay is using hibernate at the bottom, is that not hibernate-backed database Liferay supported? This should theoretically be the case, but it is not, the database supported by Liferay is as follows:

DB2, Derby, Hypersonic (HSQL), Ingres, Mysql, Oracle, P6spy, PostgreSQL, SQL Server, Sybase, etc.

Other databases By default do not provide direct support, as long as the database is hibernate support, if you want to let Liferay support, need to make some changes to the source code, the changes are not complicated. Specific can refer to the Liferay source directory under the portal-impl/src/com/liferay/portal/dao/db of the following polygons related classes.

How to get the JDBC connection string in code connection

Sometimes maybe for this reason, we are going to get JDBC Connection connection, what do we do? It is certainly possible to use normal JDBC to read the configured parameters, but Liferay has provided us with such an API:

Dataaccess.getconnection ().

Some additional information about the database connection, such as the current database, can be obtained by DBFACTORYUTIL.GETDB () and obtaining the relevant method.

Liferay 6 Development Learning (26): Database Connectivity related issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.