3 Replies Latest reply on Aug 21, 2002 11:21 AM by davidjencks

    How I can get JDBC_URL and jdbc.driver?

    kafka

      Hello,
      I have JBoss 3.0.0 and postgres database.
      How I can get JDBC_URL and jdbc.driver?
      I tray with this code:
      public static final String JDBC_URL = "connection-url";
      public Connection getConnection() throws SQLException
      {
      try
      {
      String jdbcURL =(String) env.get(JDBC_URL);
      System.out.println(jdbcURL );
      String drivers =(String)env.get("jdbc.drivers");
      DriverManager.setLogStream(System.out);
      return DriverManager.getConnection(jdbcURL, env);
      }
      catch(SQLException ee)
      {
      System.out.println(ee);
      }
      return null;
      }
      But I get errors, when I use env.get()....
      Maybe somebody can send sample.
      thanks

        • 1. Re: How I can get JDBC_URL and jdbc.driver?
          davidjencks

          Please use a connection pool. FInd postgres-service.xml in docs/examples/jca (or nearby), change it to match your configuration, and put it in server/default/deploy.

          When you need a connection,
          DataSource ds = (DataSource)new InitialContext.lookup("java:/PostgresDS");
          Connection c = ds.getConnection();
          try {
          //do work
          }
          finally
          {
          c.close();
          }

          • 2. Re: How I can get JDBC_URL and jdbc.driver?
            kafka

            Thanks for reply.
            Now I persuade, what my postgres-service.xml is not good.
            If I have postgres-ds.xml, then I will get this warrining:

            18:59:32,655 INFO [MainDeployer] Starting deployment of package: file:/C:/bean2
            /jboss/server/default/deploy/postgres-ds.xml
            18:59:32,675 INFO [MainDeployer] Deployment of package: file:/C:/bean2/jboss/se
            rver/default/deploy/postgres-ds.xml is waiting for an appropriate deployer.

            Later, when client is runing:
            19:00:38,920 INFO [STDOUT]javax.naming.NameNotFoundException: PostgresD
            S not boundend
            My postgres-ds.xml:
            <?xml version="1.0" encoding="UTF-8" ?>

            -
            - <local-tx-datasource>
            <jndi-name>PostgresDS</jndi-name>
            <connection-url>jdbc:postgresql://www.aaa.com:5432/nasa</connection-url>
            <driver-class>org.postgresql.Driver</driver-class>
            <user-name>aaa</user-name>
            aaa
            </local-tx-datasource>




            If I load this postgres-service.xml:

            <?xml version="1.0" encoding="UTF-8"?>


            <!-- ==================================================================== -->
            <!-- New ConnectionManager setup for default postgres dbs -->
            <!-- ==================================================================== -->


            <!--make the rar deploy! hack till better deployment-->
            jboss.jca:service=RARDeployer


            <depends optional-attribute-name="ManagedConnectionFactoryName">
            <!--embedded mbean-->

            <!--hack-->
            <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=Minerva JDBC LocalTransaction ResourceAdapter
            jboss:service=Postgres

            <!--real attributes-->


            <config-property>
            <config-property-name>ConnectionURL</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>jdbc:postgresql://www.aaa.com:5432/nasa</config-property-value>
            </config-property>
            <config-property>
            <config-property-name>DriverClass</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>org.postgresql.Driver</config-property-value>
            </config-property>
            <config-property>
            <config-property-name>UserName</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>aaa</config-property-value>
            </config-property>
            <config-property>
            <config-property-name>Password</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>aaa</config-property-value>
            </config-property>


            PostgresDS


            <depends optional-attribute-name="ManagedConnectionPool">
            <!--embedded mbean-->


            0
            50
            5000
            15
            <!--criteria indicates if Subject (from security domain) or app supplied
            parameters (such as from getConnection(user, pw)) are used to distinguish
            connections in the pool. Choices are
            ByContainerAndApplication (use both),
            ByContainer (use Subject),
            ByApplication (use app supplied params only),
            ByNothing (all connections are equivalent, usually if adapter supports
            reauthentication)-->
            ByContainer


            <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager
            java:/jaas/PostgresDbRealm
            java:/TransactionManager



            I will get this warrning:
            19:04:54,788 INFO [MainDeployer] Starting deployment of package: file:/C:/bean2
            /jboss/server/default/deploy/postgres-service.xml
            19:04:55,609 WARN [LocalTxConnectionManager] WARNING: UPDATE YOUR SecurityDomai
            nJndiName! REMOVE java:/jaas/
            19:04:55,839 WARN [ServiceController] jboss.jca:service=LocalTxDS,name=Postgres
            DS does not implement any Service methods
            19:04:55,849 INFO [JBossManagedConnectionPool] Creating
            19:04:55,869 INFO [JBossManagedConnectionPool] Created
            19:04:55,869 INFO [JBossManagedConnectionPool] Starting
            19:04:55,879 INFO [JBossManagedConnectionPool] Started
            19:04:55,879 INFO [MainDeployer] Successfully completed deployment of package:
            file:/C:/bean2/jboss/server/default/deploy/postgres-service.xml

            And when I run client I get errors:
            19:06:24,587 INFO [STDOUT] javax.naming.NameNotFoundException: PostgresD
            S not boundend

            Where I can find step by step config, to make good conection to database?
            I buy JBOSS 3.0 ADMINISTRATION AND DEVELOPMENT DOCUMENTATION, but did not find property information...

            • 3. Re: How I can get JDBC_URL and jdbc.driver?
              davidjencks

              *-ds.xml files only work with jboss 3.2 and 4.

              Please use a *-service.xml file that came with your binary download or has a cvs tag for the jboss version you have. Your postgres-service.xml file looks like it is from 3.0RC1 or so. In particular it is using a jca jdbc wrapper that was removed around april.