1 Reply Latest reply on Feb 16, 2007 2:53 PM by Elias Ross

    Jboss DataSource Lookup question

    Bill Lin Newbie

      hi,
      I am new beginner of Jboss. Hope somebody can give me a clear concept of the following questions. Thanks in advance.
      I setted up the DataSource in mysql-ds.xml file as follows:

      <local-tx-datasource>
      <jndi-name>MySqlDS</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/home</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>
      admin

      <min-pool-size>5</min-pool-size>
      <max-pool-size>20</max-pool-size>
      <idle-timeout-minutes>5</idle-timeout-minutes>
      </local-tx-datasource>

      and when I start up the jboss, jboss printed out the following information:
      Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS'

      and in the program, I was supposed to code as follows:
      Context ctx = new InitialContext();
      ds = (DataSource)ctx.lookup("java:MySqlDS");

      So,
      1). I want to know why I can't replace this sentence "ds = (DataSource)ctx.lookup("java:MySqlDS");" as "ds = (DataSource)ctx.lookup("java:comp/env/MySqlDS");"?
      2). what is the difference between "java:MySqlDS" and "java:comp/env/MySqlDS"? Someone told me that "java:comp/env/MySqlDS" is mostly used in real project, but "java:MySqlDS" not.
      3). I know "java:MySqlDS" is for getting a DataSource config in the *-ds.xml file, however "java:/comp/env/MySqlDS" is for using JDBC connections, is my opinion correct?