• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why JNDI for database connection

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I came across the following code in a servlet
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup(config.getInitParameter("DATASOURCE_NAME"));
Is that soething to do with JNDI data connection. is that refers a JDBC driver.
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is the way of obtaining a data source via JNDI.
The data source could have been defined in the application server and given a jndi name. This JNDI name could be stored in some configuration file, (could be just a whole bunch of Static final parameters).. and this is being retrieved and used.
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well Nagendra
i got a confusion about JNDI processing here..
JNDI will look for datasource(name)depending upon the key provided in configuration file.
How do it gets the location of this database?
thanks
Vikas

Originally posted by Nagendra Prasad:
It is the way of obtaining a data source via JNDI.
The data source could have been defined in the application server and given a jndi name. This JNDI name could be stored in some configuration file, (could be just a whole bunch of Static final parameters).. and this is being retrieved and used.

 
Nagendra Prasad
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
vikas
i can reply to this in the context in which i have addressed the problem.
The datasource is defined for the app server. THis I achieved using the admin interface for the app server. The server resources generally have a section where u ca specify the JDBC providers. In the same place u can provide a database name, username and password.
While defining, once can provide a JNDI mapping (or name) for this datasource and reference it as such within the application.
 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well Nagendra i m also asking in same context.
lets say my database for which datasource is to be created is at some other location.
In configuration section, we also hard code the machine location of database.
Is it possible to move databse location to some other machine while the application is running?
Like in case we want to move EJB to other location,the user is still serviced due to inbuilt location transparency property.
Can we utilize location transparency in case of persistence server also(database)without hardcoding machine location in configuration section?
thanks.

Originally posted by Nagendra Prasad:
vikas
i can reply to this in the context in which i have addressed the problem.
The datasource is defined for the app server. THis I achieved using the admin interface for the app server. The server resources generally have a section where u ca specify the JDBC providers. In the same place u can provide a database name, username and password.
While defining, once can provide a JNDI mapping (or name) for this datasource and reference it as such within the application.

 
Nagendra Prasad
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vikas...
to be honest.. i am not sure of answer for this...
i was (and still am) under the impression that any change to config parameters of an appserver needs a restart... that being the case I am not sure if service level can continously be maintained..
even in a clustered environment, i am wondering if such a thing is easily possible..
not sure... but a good trail tothink of .. if u find anything.. could you please post? If I get something out of my research, I shall..
 
ramdas pradeep kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem was solved.

Regarding the discussion about the db path:
I am telling in the context of Tomcat server.
in the config/server.xml we have to create context for each application. there we give all the resource and resource parameters.
in this point we specify some DSN or file path. like
........
<parameter>
<name>url</name>
<value>jdbc:interbase://localhost/c:/app/dbs_myapp.gdb</value>
</parameter>
........
.......
but don't know about EJBs and all
reply
    Bookmark Topic Watch Topic
  • New Topic