2 Replies Latest reply on Jun 2, 2005 10:28 AM by Francois Groenewald

    Difficulty accessing Postgres.

    Neil McFarlane Novice

      Howdy.

      I'm currently working on a Struts project using EJBs and I'm trying to connect my Entity Beans to my Postgres database.

      Currently however, this the code I get when I deploy:
      [CODE]
      16:45:10,939 INFO [MainDeployer] Starting deployment of package: file:/D:/x/sys/jboss-3/server/default/deploy/cpb.ear
      16:45:10,949 INFO [EARDeployer] Init J2EE application: file:/D:/x/sys/jboss-3/server/default/deploy/cpb.ear
      16:45:11,710 INFO [EjbModule] Creating
      16:45:11,720 INFO [EjbModule] Deploying BaseItem
      16:45:11,730 INFO [EjbModule] Deploying TestSession
      16:45:11,750 INFO [EjbModule] Deploying ASecond
      16:45:11,760 INFO [EntityContainer] Creating
      16:45:11,770 INFO [EntityInstancePool] Creating
      16:45:11,770 INFO [EntityInstancePool] Created
      16:45:11,770 INFO [EntityContainer] Created
      16:45:11,780 INFO [StatelessSessionContainer] Creating
      16:45:11,790 INFO [StatelessSessionInstancePool] Creating
      16:45:11,790 INFO [StatelessSessionInstancePool] Created
      16:45:11,800 INFO [StatelessSessionContainer] Created
      16:45:11,800 INFO [StatelessSessionContainer] Creating
      16:45:11,810 INFO [StatelessSessionInstancePool] Creating
      16:45:11,810 INFO [StatelessSessionInstancePool] Created
      16:45:11,810 INFO [StatelessSessionContainer] Created
      16:45:11,810 INFO [EjbModule] Created
      16:45:11,820 INFO [EjbModule] Starting
      16:45:11,820 INFO [EntityContainer] Starting
      16:45:33,071 ERROR [EntityContainer] Starting failed
      org.jboss.deployment.DeploymentException: Connection timed out: connect; - nested throwable: (java.net.ConnectException: Connection timed out: connect)
      .
      .
      .
      [/CODE]

      I'm pretty sure it's because I haven't configured my connection properly, but I'm not sure where I've gone wrong.

      The following are my configuration files. A = Address, P = Port, D = Database. I know that the A, P, and D are correct as I can connect to the database through pgAdmin.

      property-ds.xml
      [CODE]
      <?xml version="1.0" encoding="UTF-8"?>


      <local-tx-datasource>
      <jndi-name>PostgresDS</jndi-name>
      <connection-url>jdbc:postgresql://A:P/D</connection-url>
      <driver-class>org.postgresql.Driver</driver-class>
      <user-name>myName</user-name>
      myPass
      <min-pool-size>5</min-pool-size>

      </local-tx-datasource>

      [/CODE]

      jbosscmp-jdbc.xml
      [CODE]
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">

      <jbosscmp-jdbc>

      java:/PostgresDS
      <datasource-mapping>PostgreSQL</datasource-mapping>
      <create-table>true</create-table>
      <remove-table>false</remove-table>


      <enterprise-beans>

      <!--
      To add beans that you have deployment descriptor info for, add
      a file to your XDoclet merge directory called jbosscmp-jdbc-beans.xml
      that contains the markup for those beans.
      -->


      <ejb-name>BaseItem</ejb-name>

      <table-name>bse_item</table-name>

      <cmp-field>
      <field-name>item_num</field-name>

      </cmp-field>

      <!-- jboss 3.2 features -->
      <!-- optimistic locking does not express the exclusions needed -->


      </enterprise-beans>

      </jbosscmp-jdbc>
      [/CODE]

      Does anyone have any ideas of what the problem might be?

        • 1. Re: Difficulty accessing Postgres.
          Neil McFarlane Novice

          Looks like that came out a bit sloppy, let me try some of those again.

          Message when deploying

          16:45:10,939 INFO [MainDeployer] Starting deployment of package: file:/D:/x/sys/jboss-3/server/default/deploy/cpb.ear
          16:45:10,949 INFO [EARDeployer] Init J2EE application: file:/D:/x/sys/jboss-3/server/default/deploy/cpb.ear
          16:45:11,710 INFO [EjbModule] Creating
          16:45:11,720 INFO [EjbModule] Deploying BaseItem
          16:45:11,730 INFO [EjbModule] Deploying TestSession
          16:45:11,750 INFO [EjbModule] Deploying ASecond
          16:45:11,760 INFO [EntityContainer] Creating
          16:45:11,770 INFO [EntityInstancePool] Creating
          16:45:11,770 INFO [EntityInstancePool] Created
          16:45:11,770 INFO [EntityContainer] Created
          16:45:11,780 INFO [StatelessSessionContainer] Creating
          16:45:11,790 INFO [StatelessSessionInstancePool] Creating
          16:45:11,790 INFO [StatelessSessionInstancePool] Created
          16:45:11,800 INFO [StatelessSessionContainer] Created
          16:45:11,800 INFO [StatelessSessionContainer] Creating
          16:45:11,810 INFO [StatelessSessionInstancePool] Creating
          16:45:11,810 INFO [StatelessSessionInstancePool] Created
          16:45:11,810 INFO [StatelessSessionContainer] Created
          16:45:11,810 INFO [EjbModule] Created
          16:45:11,820 INFO [EjbModule] Starting
          16:45:11,820 INFO [EntityContainer] Starting
          16:45:33,071 ERROR [EntityContainer] Starting failed
          org.jboss.deployment.DeploymentException: Connection timed out: connect; - nested throwable: (java.net.ConnectException: Connection timed out: connect)
          .
          .
          .
          


          property-ds.xml
          <?xml version="1.0" encoding="UTF-8"?>
          
          
          <local-tx-datasource>
          <jndi-name>PostgresDS</jndi-name>
          <connection-url>jdbc:postgresql://A:P/D</connection-url>
          <driver-class>org.postgresql.Driver</driver-class>
          <user-name>myName</user-name>
          <password>myPass</password>
          <min-pool-size>5</min-pool-size>
          
          </local-tx-datasource>
          


          jbosscmp-jdbc.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
          
          <jbosscmp-jdbc>
           <defaults>
           <datasource>java:/PostgresDS</datasource>
           <datasource-mapping>PostgreSQL</datasource-mapping>
           <create-table>true</create-table>
           <remove-table>false</remove-table>
           </defaults>
          
           <enterprise-beans>
          
           <!--
           To add beans that you have deployment descriptor info for, add
           a file to your XDoclet merge directory called jbosscmp-jdbc-beans.xml
           that contains the <entity></entity> markup for those beans.
           -->
          
           <entity>
           <ejb-name>BaseItem</ejb-name>
          
           <table-name>bse_item</table-name>
          
           <cmp-field>
           <field-name>item_num</field-name>
          
           </cmp-field>
          
          <!-- jboss 3.2 features -->
          <!-- optimistic locking does not express the exclusions needed -->
           </entity>
          
           </enterprise-beans>
          
          </jbosscmp-jdbc>
          


          Does anyone see anything obviously wrong with my set up?

          • 2. Re: Difficulty accessing Postgres.
            Francois Groenewald Newbie

            First things first, ensure that you can actually connect to the database instance using the address and port you have given in the jboss-jdbc.xml file by using the psql commandline utility (psql -H A -p P D).

            Secondly, I have mine working on windows with the following connection settings in $(jboss)/server/default/deploy/postgres-ds.xml:

            <datasources>
             <local-tx-datasource>
             <jndi-name>ModularEVD</jndi-name>
             <connection-url>jdbc:postgresql://192.168.62.54:5432/evd</connection-url>
             <driver-class>org.postgresql.Driver</driver-class>
             <user-name>evd</user-name>
             <password>evd</password>
             </local-tx-datasource>
            
             <local-tx-datasource>
             <jndi-name>PostgresDS</jndi-name>
             <connection-url>jdbc:postgresql://192.168.62.54:5432/evd</connection-url>
             <driver-class>org.postgresql.Driver</driver-class>
             <user-name>jboss</user-name>
             <password>jboss</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>
            
            


            I have never seen it done through a property-ds.xml file but that's probably just me :P

            Hope it helps.