i have problems understanding jndi.
i'm this far: i deployed the sun application server and i'm working through
the examples (Duke bookstore, ...). Sometimes i see code which does a
lookup to a JNDI-name like this:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/BookDB");
con = ds.getConnection();
But what is happening here? the lookup to jdbc/BookDB returns a Datasource??
Where does that come from?
This Datasource is configured in the server-configuration.
Why then use this mechanism? Everything you lookup via JNDI is specified in
the server configuration. What i would expect is that jndi lets me access
configuration information (for example connection settings for databases).
For example when i go from development to production environment, the
database url changes. So i need only change the configuration information
in the jndi-tree. But that doesn't seem to be the case. Anybody can shed
some light on this? thank you very much.
when i look into the server configuration, i see defined jndi-names and the
properties that they should have
for example (snippet at end of message)
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/__TimerPool"
object-type="system-admin" pool-name="__TimerPool"/>
<jdbc-resource enabled="true" jndi-name="jdbc/PointBase"
object-type="user" pool-name="PointBasePool"/>
<jdbc-resource enabled="true" jndi-name="jdbc/BookDB" object-type="user"
pool-name="PointBasePool"/>
<mail-resource debug="false" enabled="true" from="xy*@foo.com"
host="localhost" jndi-name="mail/Session" object-type="user"
store-protocol="imap" store-protocol-class="com.sun.mail.imap.IMAPStore"
transport-protocol="smtp"
transport-protocol-class="com.sun.mail.smtp.SMTPTransport" user="nobody"/>
<jdbc-connection-pool connection-validation-method="auto-commit"
datasource-classname="com.pointbase.xa.xaDataSource"
fail-all-connections="false" idle-timeout-in-seconds="300"
is-connection-validation-required="false"
is-isolation-level-guaranteed="true" max-pool-size="32"
max-wait-time-in-millis="60000" name="__TimerPool" pool-resize-quantity="2"
res-type="javax.sql.XADataSource" steady-pool-size="8">
<property name="DatabaseName"
value="jdbc:pointbase:embedded:ejbtimer,database.h ome=${com.sun.aas.instanceRoot}/lib/databases"/>
<property name="User" value="pbPublic"/>
<property name="Password" value="pbPublic"/>
</jdbc-connection-pool>
<jdbc-connection-pool connection-validation-method="auto-commit"
datasource-classname="com.pointbase.xa.xaDataSource"
fail-all-connections="false" idle-timeout-in-seconds="300"
is-connection-validation-required="false"
is-isolation-level-guaranteed="true" max-pool-size="32"
max-wait-time-in-millis="60000" name="PointBasePool"
pool-resize-quantity="2" res-type="javax.sql.XADataSource"
steady-pool-size="8">
<property name="DatabaseName"
value="jdbc:pointbase:server://localhost:9092/sun-appserv-samples"/>
<property name="Password" value="pbPublic"/>
<property name="User" value="pbPublic"/>
</jdbc-connection-pool>
</resources>