Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Smilelws2010 lwz
Service Builder - and additional jdbc connection to database
June 12, 2013 11:20 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

HI

Can a liferay custom portlet built using service builder ( crud operation on database) use a separate jdbc connection also within the same portlet to talk to database?

Much appreciate if you can guide me.

Smile
Brian Scott Schupbach
RE: Service Builder - and additional jdbc connection to database
June 12, 2013 12:12 PM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

In the META-INF folder of your portlet create a context.xml file and define the new connection.

Then to connect

1
2DataSource ds = (DataSource)envContext.lookup("jdbc/connectionInContextXML");
3            
4Connection  conn = ds.getConnection();
Smilelws2010 lwz
RE: Service Builder - and additional jdbc connection to database
June 12, 2013 12:41 PM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

Thanks Brian for the quick suggestion and reply.

And you can query the database from within your XXXserviceImpl class normally?

Best Regards,
SMile
Brian Scott Schupbach
RE: Service Builder - and additional jdbc connection to database
June 12, 2013 12:44 PM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

Correct. You should try it out and if you have errors that you can't figure out, post the log in one of the forums. However, I think you'll find it's pretty easy to figure out.
Good luck
Smilelws2010 lwz
RE: Service Builder - and additional jdbc connection to database
June 18, 2013 9:30 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

Thanks Brian for the quick guidance

I could use the simple jdbc as well as jndi connection in addition to SB from the porlet.properties file. I did not have to make the context file under meta-inf. Is that a practice?

Thanks
Smile