• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Database Connection

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Have a good day...
we can implement connection using two ways..
1)first, jndi - initial context
2)second , class.forname()-driver manager

in these ways , which is good way..and what is the diffrence between this ?
when implement jndi or driver manager... ?
please clarify this.

Thanks in anticipation.

rgds,
Nimish
[ September 02, 2005: Message edited by: Nimish Patel ]
 
Author
Posts: 531
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Using the manager to get the connection is hard code way
and using jndi gives you the ability to change the connection properties in deployment .
using manager make you coupled within the connection you made , and in using jndi you are not.
another thing :
I used jndi and datasources while i need the conection to be managed by container and i need connection pooling.
I think its another benefits of using container managed (jndi based) connection management than plain jdbc one.
hope it helps
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Obtaining the Connection from JNDI:
1)That Connection is a Dynamic connection.
2)In JNDI we defined some connection previously (Connectionpool) from here we are obtaining the predefined connection.
3)High performance.
Obtaining the Connection from DriverManger:
1) Is a static connection.
2) We can create our own connection object here.
3)Poor performance for this connection.
Hope that some how cleare.
Regards,
G Sirish Reddy.,
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get accustomed to obtaining a DataSource from a JNDI tree and using it to obtain your Connection. This is the way to write J2EE-compliant apps.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Datasource to get connection to DB2. When would I need to use ID and password with getConnection? Can I getConnection without ID and password?
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No password is needed to get a Connection as the password is supplied on creation of the connection pool on server startup. Each instance in the pool will maintain a connection to the DB. When you look up a data source via JNDI and access a database connection, you get a stub for the Connection instance in the server process.
 
Dong Hoang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this mean I define a default ID and password for DB2 in the server?
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, each application server its own way of configuring the username and password.
 
Dong Hoang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if I want DB2 to use the ID and password of the user that login from a login page? Can the default ID and password in the server be overwritten in my application?
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dong Hoang:
What if I want DB2 to use the ID and password of the user that login from a login page? Can the default ID and password in the server be overwritten in my application?


You can't use a custom user id and password when using the DataSource from the app server. Typically in a web app, you just authenticate the user and use an "application id" for the database access.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure what you meant by "application id" for database access. How do I get this application id?
 
Jeanne Boyarsky
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don,
An "application id" is just a regular database id. You create a user for the database, say "myAppId." Then you use that id with the datasource.

The idea is that if a user is in your application to execute code against the datasource, he/she has already been authenticated.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to know how making use of jndi and datasource gives u flexibility of changing the properties and datasource?

please explain.
 
Jeanne Boyarsky
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sri,
Welcome to JavaRanch! Note that it is ok to ask a new question in a new thread. No need to bump old threads.

Using JNDI to get the datasource allows you to keep all the datasource's information on the server. In this way, it is completely independent of the code. You just change the properties through the server's interface and the code doesn't even have to know that it changed.
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic