1 Reply Latest reply on Aug 13, 2006 4:37 PM by peterj

    how get the datasource

    joy_wind

      Hi,I have config a datasource like the following:

      <local-tx-datasource>
      <jndi-name>PostgresDS</jndi-name>
      <connection-url>jdbc:postgresql://localhost:5432/eai</connection-url>
      <driver-class>org.postgresql.Driver</driver-class>
      <user-name>postgres</user-name>
      postgres
      <min-pool-size>5</min-pool-size>
      <max-pool-size>100</max-pool-size>
      <new-connection-sql>select 1</new-connection-sql>
      <check-valid-connection-sql>select 1</check-valid-connection-sql>

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->

      <type-mapping>PostgreSQL 7.2</type-mapping>

      </local-tx-datasource>


      Then

      1, how can I get the datasource object so to get a connection ? some code snippet will be appreciated.

      2,My web app is in the save JVM,so could i get the datasource directly without a jndi lookup (may fetch the datasource mbean directly ?)?

      3,Is the database connections REALLY been pooled ,according the config like above ?

      4,how to config to let jboss server initiate serveral database connection when startup?

      I'm totally new to jboss.I have searched the web for a while but find no result.Anyone can help me ? Thanks!

        • 1. Re: how get the datasource
          peterj

          1 & 2) You should get the data source via JNDI, as follows:

          InitialContext ctx = new InitialContext();
          DataSource ds = (DataSource)ctx.lookup("PostgresDS");
          Connection conn = ds.getConnection();
          -- do stuff with the connection --
          conn.close();


          3) Yes. The close() method, above, returns the connection to the pool.

          4) You have already done that. There are 5 initial connection established. You will have at most 100 connections. Though I can't remember off hand if the connections are established at server startup or the first time you attempt to access one. I think it is the later, in which case you could make initialization code in your app access a connection, that would get the connections established at server startup time.