Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
billy chan
access jdbc/liferayPool
January 9, 2008 6:22 PM
Answer

billy chan

Rank: Junior Member

Posts: 43

Join Date: November 19, 2007

Recent Posts

I want to create a protlet which need to access the liferay's DB. I know liferay have a configuration --- jdbc/liferayPool. However, when i try to lookup jdbc/liferaypool or java:comp/env/jdbc/LiferayPool, both throw exception say they are not exist in jndi.
And i have try to use com.liferay.portal.jndi.PortalJNDIImpl to get the connection. But it cost deploy error( it get a listener error)

My question is: How can i get the connection for liferaypool? Since i don't want to copy the jndi config to /conf/content.xml

I am using liferay 4.3.5 with tomcat 5.5

Thank you ar!
Alex Wallace
RE: access jdbc/liferayPool
January 9, 2008 7:49 PM
Answer

Alex Wallace

Rank: Liferay Master

Posts: 640

Join Date: November 4, 2007

Recent Posts

i have not tried what you want to do, but it should be possible... did you reference the resource in web.xml of your portlet?
billy chan
RE: access jdbc/liferayPool
January 9, 2008 8:42 PM
Answer

billy chan

Rank: Junior Member

Posts: 43

Join Date: November 19, 2007

Recent Posts

Yes, i have , but still can not access liferaypool!
Ray Augé
Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
January 9, 2008 9:11 PM
Answer

Ray Augé

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1171

Join Date: February 7, 2005

Recent Posts

> Yes, i have , but still can not access liferaypool!

In tomcat you have to place the pool in the global classloader...

for example, add this to server.xml inside the "GlobalNamingResources":

 1  <!-- Global JNDI resources -->
 2  <GlobalNamingResources>
 3
 4          ....
 5
 6      <Resource
 7          name="LiferayPool"
 8          auth="Container"
 9          type="javax.sql.DataSource"
10          driverClassName="com.mysql.jdbc.Driver"
11
12url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8"
13          username="xxx"
14          password="xxx"
15          maxActive="100"
16          maxIdle="30"
17          maxWait="10000"
18      />
19
20      <Resource
21          name="LiferayMailSession"
22          auth="Container"
23          type="javax.mail.Session"
24          mail.transport.protocol="smtp"
25          mail.smtp.host="192.168.0.1"
26      />
27  </GlobalNamingResources>


Then in all the webapps that want to use this pool, setup their
context.xml (in the case of the portal webapp, in ROOT.xml) to contain
the following:

1    <ResourceLink name="jdbc/LiferayPool" global="LiferayPool"/>
2    <ResourceLink name="mail/MailSession" global="LiferayMailSession"/>


Don't forget the delete the other references having the same names...

Now all your webapps can use the same pool.


Hope that helps!
billy chan
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
January 9, 2008 10:31 PM
Answer

billy chan

Rank: Junior Member

Posts: 43

Join Date: November 19, 2007

Recent Posts

thanks you for you help! I know how to do!
From you answer, i know what is my problem i get before!
Thanks again!
Roman Hoyenko
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
January 10, 2008 8:40 AM
Answer

Roman Hoyenko

Rank: Liferay Master

Posts: 868

Join Date: October 8, 2007

Recent Posts

Ray, thanks for your post, it is very useful. I am going to put it into FAQ.
Ray Augé
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
January 10, 2008 10:56 AM
Answer

Ray Augé

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1171

Join Date: February 7, 2005

Recent Posts

> Ray, thanks for your post, it is very useful. I am going to put it into FAQ.

Thank you Roman, for keeping us so organized. emoticon
Brian Chan
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
January 10, 2008 7:16 PM
Answer

Brian Chan

LIFERAY STAFF

Rank: Liferay Master

Posts: 751

Join Date: August 4, 2004

Recent Posts

You can also...

com.liferay.portal.kernel.jndi.PortalJNDIUtil.getDataSource() from any portlet.
billy chan
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
January 13, 2008 6:10 PM
Answer

billy chan

Rank: Junior Member

Posts: 43

Join Date: November 19, 2007

Recent Posts

Hello, Brian Chan
I have tried to use com.liferay.portal.kernel.jndi.PortalJNDIUtil.getDataSource(), but i get a deploy error: said some listener error!
Do i did something wrong?
Thanks
billy chan
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
January 13, 2008 6:14 PM
Answer

billy chan

Rank: Junior Member

Posts: 43

Join Date: November 19, 2007

Recent Posts

Hello Ray Auge,
Thank you for your help!
I find out a similar way to get liferaypool in a portlet!
Copy the Resource from Root.xml to /conf/context.xml, look like this
<Context>
//another Resource.....
<Resource
name="jdbc/LiferayPool" auth="Container" type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/lportal"
username="username" password="password" maxActive="20"
/>
</Context>
This is also can work!
David Latty
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
July 7, 2008 8:19 AM
Answer

David Latty

Rank: Junior Member

Posts: 96

Join Date: June 15, 2008

Recent Posts

I dont seem to have as much luck as everyone else. I get the same error

11:16:07,608 ERROR [DynamicDialect:123] org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot creat
e JDBC driver of class '' for connect URL 'null'

I tried copying the resource definition into server.xml, then referencing from ROOT.xml

<ResourceLink name="jdbc/LiferayPool" global="LiferayPool"/>

but that didnt seem to help any. I still get the same error.
David Latty
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
July 7, 2008 8:51 AM
Answer

David Latty

Rank: Junior Member

Posts: 96

Join Date: June 15, 2008

Recent Posts

Some information that may help

pre existing tomcat 6, liferay 5 deployment

I do not want to remove the ROOT application, so liferay application is in context "/liferay-portal-5.0.1" (though once i fix the current issue, i may change to "/liferay").

I followed the docs by placing ROOT.xml in "\conf\Catalina\localhost" - is this correct to the above statement?

I still get

Starting Liferay Enterprise Portal 5.0.1 (Luther / Build 5001 / April 14, 2008)
11:44:21,331 ERROR [DynamicDialect:123] org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot creat
e JDBC driver of class '' for connect URL 'null'
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect UR
L 'null'


Ive also tried using the context name ("/liferay-portal-5.0.1") in the context path param of the ROOT.xml file, but that didnt seem to work either.
David Latty
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
July 7, 2008 10:18 AM
Answer

David Latty

Rank: Junior Member

Posts: 96

Join Date: June 15, 2008

Recent Posts

Solved - at least the sql error - by naming my copying ROOT.xml and pasting in same folder to name - which is the same as my context - liferay-portal-5.0.1.xml.

No SQL error - Yet.

Check out

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

for some info
Auditya manikanta Vadrevu
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
August 12, 2008 5:00 AM
Answer

Auditya manikanta Vadrevu

Rank: Liferay Master

Posts: 621

Join Date: May 6, 2008

Recent Posts

hi ray auge,

i have done all the steps same as in the post but how to retrieve the values in my application (for example in struts liferay portlet, how to use the values in jsp)
Auditya manikanta Vadrevu
RE: Re: [Liferay Forums][3. Development]RE: access jdbc/liferayPool
August 14, 2008 12:45 AM
Answer

Auditya manikanta Vadrevu

Rank: Liferay Master

Posts: 621

Join Date: May 6, 2008

Recent Posts

hi david,

follow these steps to access liferay pool in your application


1. copy the liferay pool in to server.xml (make it global)

2. call it in your application context.xml and web.xml

and in your application

just use these statements,

Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/LiferayPool");
Connection conn123 = ds.getConnection);(