Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Smilelws2010 lwz
Service Builder - and additional jdbc connection to database
12 giugno 2013 11.20
Risposta

Smilelws2010 lwz

Punteggio: Regular Member

Messaggi: 160

Data di Iscrizione: 16 dicembre 2010

Messaggi recenti

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
12 giugno 2013 12.12
Risposta

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 329

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

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
12 giugno 2013 12.41
Risposta

Smilelws2010 lwz

Punteggio: Regular Member

Messaggi: 160

Data di Iscrizione: 16 dicembre 2010

Messaggi recenti

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
12 giugno 2013 12.44
Risposta

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 329

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

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
18 giugno 2013 9.30
Risposta

Smilelws2010 lwz

Punteggio: Regular Member

Messaggi: 160

Data di Iscrizione: 16 dicembre 2010

Messaggi recenti

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