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:

  1. is possible datasource object local hosted databases?
  2. does datasource class need published, or drivermanager connection no new class creation?
  3. 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:

  1. a basic datasource implementation produces standard connection objects not pooled or used in distributed transaction.
  2. a datasource implementation supports connection pooling produces connection objects participate in connection pooling, is, connections can recycled.
  3. 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:

  1. connecting datasource objects
  2. why use datasource instead of drivermanager?
  3. data access jdbc
  4. how retrieve db connection using datasource without jndi?
  5. best way manage db connections without jndi

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -