Ask Question. Asked 8 years, 7 months ago. Active 1 year, 11 months ago. Viewed 88k times. It is preferred over DriverManager because it allows details about the underlying data source to be transparent to the application What I am trying to understand is what the difference is between a Connection and a DataSource , and why it exists.
Improve this question. Basil Bourque k 74 74 gold badges silver badges bronze badges. LuckyLuke LuckyLuke Add a comment. Active Oldest Votes. Better scalability and maintenance For DriverManager you need to know all the details host, port, username, password, driver class to connect to DB and to get connections. Scalability: Suppose you need to create connections yourself, how would you deal with changing load, sometime you have 10 users sometime you have , you can't just get a connection whenever you need one and later 'release' it so the Database server does not get out of connections, which leads you to connection pooling.
Improve this answer. Yousha Aleayoub 3, 4 4 gold badges 44 44 silver badges 59 59 bronze badges. A4L A4L The appserver needs to know the driver to be able create the Datasource. After that it takes care of binding it to the JNDI name logical name that has been configured. Note that for this configuration step all the details driver class, url, username, password etc. If you are going to program a connection pool then you have to use DriverManager, otherwise go with Datasource.
CodeChieftain I think he means, if you want to implement a Connection Pool yourself, so there is nothing to flip. Datasource provides connection polling. Last statement states if you wish to program connection polling go for DataManager. It can be bit misleading at first. It should be if you wish to have connection polling in your app go for datasource. Note that is is very possible to programmatically create a DataSource backed by a connection pool dynamically based on user input. So I think the question is not really between a DataSource and no- DataSource , but rather between a container managed DataSource and an application managed DataSource.
Container managed DataSources are easier to manage by server-admin types. They can be tuned through the app server web UI, etcApplication managed DataSources do not have this advantage.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 3 months ago. Active 1 year, 11 months ago. Viewed 2k times. Question is basically identify the best practices on data access layer. I know very clearly following advantages Flexibility of configuration In built connection pooling mechanism But if I can sacrifice advantage of flexibility with configuration and have own connection pooling mechanism, Do I get any other benefit out of data source.
I would be looking following things How better I can design own connection pool my self? Improve this question. Satheesh Cheveri Satheesh Cheveri 3, 3 3 gold badges 23 23 silver badges 43 43 bronze badges.
Out of curiosity, why can't you use a datasource? You can configure a DataSource using a tool or manually. For example, Here is an example of a DataSource lookup:.
DataSource implementations must provide getter and setter methods for each property they support. These properties typically are initialized when the DataSource object is deployed. A simple JDBC application sample code. Data Access Technologies in Java. JDBC and Tomcat context settings. Creating Database Connection Pool in Tomcat 5.
0コメント