Fórum

Service Builder - and additional jdbc connection to database

Smilelws2010 lwz, modificado 10 Anos atrás.

Service Builder - and additional jdbc connection to database

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
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
thumbnail
Brian Scott Schupbach, modificado 10 Anos atrás.

RE: Service Builder - and additional jdbc connection to database

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
In the META-INF folder of your portlet create a context.xml file and define the new connection.

Then to connect


DataSource ds = (DataSource)envContext.lookup("jdbc/connectionInContextXML");
			
Connection  conn = ds.getConnection();

Smilelws2010 lwz, modificado 10 Anos atrás.

RE: Service Builder - and additional jdbc connection to database

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
Thanks Brian for the quick suggestion and reply.

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

Best Regards,
SMile
thumbnail
Brian Scott Schupbach, modificado 10 Anos atrás.

RE: Service Builder - and additional jdbc connection to database

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
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, modificado 10 Anos atrás.

RE: Service Builder - and additional jdbc connection to database

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
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