java - How to get a DataSource? -
i'm not how datasource
object. able use drivermanager
method obtain connection sql database running on localhost, every time try use datasource
method wind getting exceptions (mostly naming).
what wondering is:
- is possible
datasource
object local hosted databases? - does
datasource
class need published, ordrivermanager
connection no new class creation? - could show example?
a datasource
allows getting jdbc connection pool of connections. datasource
object represents particular dbms or other data source, such file. if company uses more 1 data source, deploy separate datasource
object each of them. datasource
interface implemented driver vendor. externalize db connection properties file , fetch object using jndi. using datasource
need know jndi name. application server cares details.
it can implemented in 3 different ways:
- a basic
datasource
implementation produces standard connection objects not pooled or used in distributed transaction. - a
datasource
implementation supports connection pooling produces connection objects participate in connection pooling, is, connections can recycled. - a
datasource
implementation supports distributed transactions produces connection objects can used in distributed transaction, is, transaction accesses 2 or more dbms servers.
like, in spring, can configure datasource in xml file , (1) either inject bean, (2) applicationcontext
.
datasource ds = (datasource) applicationcontextprovider. getapplicationcontext().getbean("mydatasource"); connection c = ds.getconnection();
suggested reading:
Comments
Post a Comment