Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC: Concept of DataSource

 
Neel Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need to know the concept of DataSource in Java-Database connectivity.

I have worked development of on web based applications and while working in my projects we used to have a datasource named "BankingDatasource".

I always use to just fetch the connection object in java file and write SQL query.

But I have done very less of Data base related work.

Hence I need to understand step by step process how JDBC connection , Data Source works through weblogic/ websphere.

How the Data Source is found , if there are many datasources.

Anyone Please guide.

Thanks
Neelam

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A datasource is typically a way for the server to manage the connection (or more likely connection pool) for you. A server has a map of datasources and other managed resources in a directory called the JNDI. You use a JNDI reference name in order to retrieve a reference to the datasource in your code.
 
Neel Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:A datasource is typically a way for the server to manage the connection (or more likely connection pool) for you. A server has a map of datasources and other managed resources in a directory called the JNDI. You use a JNDI reference name in order to retrieve a reference to the datasource in your code.


Thanks Jeanne.
 
Kalpesh Malbari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that the data source is a single physical connection to DB used by server to maintain multiple logical instances. Can anyone explain the technical basics behind datasource?

TIA
Kalpesh
 
Mandy Rocks
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDBC API is for Database vendor to implement it in their driver classes and Programmer to use it abstractly.

Say for instance, when we define one data source in Application Server, we provide URL, Driver class, Transaction Attribute, Application server on which we want to deploy, properties like user=scott, passowrd=tiger etc.
When we add data source to App server, we provide JNDI name to it. So, application server bound an instance of this data source object (Actually implementation is provided by Database vendor) it.

All interfaces implementation are depends on Driver we selected, interfaces like, DataSource, Connection, Statement, ResultSet etc.

So, when we want to interact with database, we will look-up for the JNDI name we have provided at creation time.


 
Kalpesh Malbari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mandy, thanks for the info..

So, in case of connection pooling, application server is responsible to manage the number of logical connections in pool over single physical connection to DB and this is where performance matters.. right?
Or are same number of physical connections maintained between application server & DB as mentioned in pool config?

I am a little curious to know about the generic concept used for implementation, are there any references explaining it?

Thanks
Kalpesh
 
Mandy Rocks
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Absolutely right.

While defining a DataSource, we provice minimum/maximum/unused no of connections we need from datasource. Indirectly it means, it will Application Server manager logical connections internally within.

When we ask datasource to give connection, it will pick up from logical connection pool and provide to you, while physical connection to DB server may remains one.

Hope, it clarify
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic