wood burning stoves 2.0*
The moose likes Websphere and the fly likes How to use PostgreSQL with WSAD 5.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "How to use PostgreSQL with WSAD 5.1" Watch "How to use PostgreSQL with WSAD 5.1" New topic

How to use PostgreSQL with WSAD 5.1

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi .
I�m trying to configure WSAD 5.1 to use PostgreSQL as the DataSource for my app. But I just can�t figure out which class I have to declare as my Pooling implementation ... nor where I can link my datasource to the physical database... (url, etc...)
Any idea ?
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
Hello Fabio
No worries.
Select UserDefined JDBC provider from the datasource tab
This is the DataSource class I assume for Postgres SQL. You might be knowing it better than I do:-)
URL should be
jdbc ostgresql://hostname ort/databaseName
Make sure you configure the jar/zip file which contains this driver classes with Websphere under CLASSPATH from JDBCProvider section.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Mahesh !

Tks 4 your help ! In fact that�s what I�ve done. The .jar classpath I put in the CLASSPATH box right under the implementation class for the driver.

But right now, I�m having this message when I try to run the app :
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
My lookup code is :
ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/db_name");
I think I might be missing some configuration detail...
Any idea ?
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
This is fine. Do this following.
If you are using java:comp/env you should make a reference entry from Web container or EJB Container. That means, based on who is making this reference to JNDI Name, you have to make this reference to Datasource from Web Deployment Descriptor from WSAD (Referecnes tab->Resource
Enter the following information
Under Resource Reference, click on Add.
give the name you coded with java:comp/env as the reference name.
say for example jdbc/postgresDs in your code it will be java:comp/env/jdbc/postgresDs
Under the details,
Type = javax.sql.DataSource
Under the Websphere bindings
JNDIName= jndiname you gave while you configured the datasource.
Hope it will help you to resolve your issue.
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
"based on who is making this reference to JNDI Name, you have to make this reference to Datasource from Web Deployment Descriptor from WSAD (Referecnes tab->Resource"
I want change it as
"based on who is making this reference to JNDI Name, you have to make this reference to Datasource from Web Deployment Descriptor from WSAD (Referecnes tab->Resource if Web projects are trying to refer the Datasource or EJB Deployment Descriptor if from the EJB Project you are trying to reference the Datasource."
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks once more . In fact , I�ve done all this procedures ...
As I�m using the 5.1 version, I wasn�t allowed to declare a V4 Datasource. Instead , I defined a V5 , which has a little bit different configuration. For instance, it claims for a HelperClass... and I don�t have the slightest idea of what to put there... I tried com.ibm.websphere.rsadapter.ConnectJDBCDataStoreHelper and some other available options in the combobox, but, with no idea concerning its implications...
Nevertheless, I�m still having problems ... as follows...
[07/11/03 10:45:07:031 BRST] 509d7a82 WSRdbDataSour u Database version is
[07/11/03 10:45:07:031 BRST] 509d7a82 WSRdbDataSour u JDBC Driver version is
PostgreSQL 7.3.3 JDBC2 jdbc driver build 110
[07/11/03 10:45:07:172 BRST] 509d7a82 FreePool E J2CA0046E: O m�todo createManagedConnectionWithMCWrapper detectou uma exce��o durante a cria��o de ManagedConnection para o recurso jdbc/jsaude, emitindo ResourceAllocationException. Exce��o original: java.lang.reflect.UndeclaredThrowableException: java.lang.reflect.InvocationTargetException: Transaction isolation level 4 is not supported.
at org.postgresql.jdbc1.AbstractJdbc1Connection.setTransactionIsolation(AbstractJdbc1Connection.java:1124)
at java.lang.reflect.Method.invoke(Native Method)
at org.postgresql.jdbc2.optional.PooledConnectionImpl$ConnectionHandler.invoke(PooledConnectionImpl.java:242)
at $Proxy0.setTransactionIsolation(Unknown Source)
at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.setTransactionIsolation(WSRdbManagedConnectionImpl.java:2757)
at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.synchronizePropertiesWithCRI(WSRdbManagedConnectionImpl.java:1388)
at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.<init>(WSRdbManagedConnectionImpl.java:411)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.createManagedConnection(WSManagedConnectionFactoryImpl.java:569)
at com.ibm.ejs.j2c.poolmanager.FreePool.createManagedConnectionWithMCWrapper(FreePool.java:1244)
at com.ibm.ejs.j2c.poolmanager.FreePool.createOrWaitForConnection(FreePool.java:1030)
at com.ibm.ejs.j2c.poolmanager.PoolManager.reserve(PoolManager.java:1590)
at com.ibm.ejs.j2c.ConnectionManager.allocateMCWrapper(ConnectionManager.java:658)
at com.ibm.ejs.j2c.ConnectionManager.allocateConnection(ConnectionManager.java:446)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:215)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:190)
at br.com.japinfo.pattern.locator.ServiceLocator.getConnectionPoolJNDI(ServiceLocator.java:82)
at br.com.japinfo.pattern.locator.ServiceLocator.getConnection(ServiceLocator.java:49)
at br.com.japinfo.pattern.dao.BaseDAO.getConnection(BaseDAO.java:27)
at br.com.japinfo.saude.jsaude.administracao.cadastro.cidadao.dao.CidadaoDAO.getListVO(CidadaoDAO.java:539)
at br.com.japinfo.saude.jsaude.administracao.cadastro.cidadao.action.ConsultarCidadaoAction.execute(ConsultarCidadaoAction.java:64)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:435)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)

And I�m still figthing the problems..
Any idea will be greatly appreciated...

Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
It is bcos it is based on J2C Specification. Your datasource needs to work with ResourceAdaptors to work with the Database to get connections. Basically ResourceAdaptors implement the CCI interface and each EIS should provide an implementation for this CCI inteface to work with Application Servers. From the list of helperclasses in Websphere5.0, I cant see one but definitely you should be able to find out how your own ResourceAdaptor implementation can be installed in Websphere.
Here is the sequence
Websphere Connection Manager ->Resource Adaptor ->Database.
I agree. Here's the link: http://aspose.com/file-tools
subject: How to use PostgreSQL with WSAD 5.1