• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Postgre Datasource for JBoss

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please somone tell me how to configure a datasource in JBoss3.2.2 for PostgreSQL?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mandar !
Well , I�ve already done this , but I�m not sure if I�m able to describe all the steps... But I think the following recipe can take you there..
In web.xml :
<resource-ref >
<res-ref-name>jdbc/MyDSName</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
In the C:\jboss-3.2.2_jetty-4.2.11\server\YourApp\deploy , you must create the postgres-ds.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: postgres-ds.xml,v 1.1.2.1 2003/09/05 16:38:24 patriot1burke Exp $ -->
<!-- ==================================================================== -->
<!-- Datasource config for Postgres -->
<!-- ==================================================================== -->

<datasources>
<local-tx-datasource>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc ostgresql://yourserver ort/appcontext</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>user</user-name>
<password>password</password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
</local-tx-datasource>
</datasources>
And finally, you have to create a jboss-web.xml in your WEB-INF app directory as follows :

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/MyDSName</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/PostgresDS</jndi-name>
</resource-ref>
</jboss-web>
Then , in order to get the DS object, you have this code (using JNDI) :
ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/MyDSName");

Everything I told you is correct, but I don�t remember if it�s all you�ve got to set everything up or if there�s something missing... so... give it a try and if you have problems, let me know...
Best wishes,
F�bio
 
Mandar Kulkarni
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fabio,
Thanx for ur reply.But i am using JBoss for an Enterprise Application and not for Web Application.So can u tell me the configuration settings for EJB Development?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mandar !
Sorry... but that�s all I know about this issue...
Good luck !
F�bio
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Mandar Kulkarni:
Hi Fabio,
Thanx for ur reply.But i am using JBoss for an Enterprise Application and not for Web Application.So can u tell me the configuration settings for EJB Development?


Once you add the postgres datasource xml in your /deploy directory, jboss should load the datasource into a jndi name you can use in your ejb. There are many examples of how datasources should look like in $jboss_home/docs/examples/jca (if your using 3.2.2).
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks fabio for the help, it works like a breeze, from the first shot

this really saved me a lot of time

keep the good spirit

regards,

Drepac
 
Are you here to take over the surface world? Because this tiny ad will stop you!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic