I’ll briefly describe how you can create data sources using the Application Server Control. Here are the steps:
On the Job: Your default data-sources.xml file provides predefined data sources that may suit your needs.
A DataSource object is used by developers to provide a logical representation of a database. It’s the job of the deployer to map this logical representation to a physical database. Using the logical DataSource object to look up the JNDI, the J2EE applications will retrieve the database names so they can connect to them. The deployer first uses the J2EE application file (EAR file), to locate the DataSource references in the deployment descriptor. The deployer will then create mappings between the database schemas matching the DataSource requirements, so the application can connect to it. You must use an emulated data source for a single-phase commit, and you can utilize the default data source (data-sources.xml) for this purpose. Here’s the default data-sources.xml file: <data-source Plug in your database URL information instead of the default URL shown in the data-sources.xml file. You must do this for each of the databases that are part of the transaction. The data source retrieval, as mentioned earlier, is done through a JNDI lookup. The JNDI name is shown by the ejb-location attribute. Retrieving the Data Source Connection Your first task before using the database for queries is to retrieve a connection to the database. To retrieve the database connection, you can perform a lookup on the JNDI name bound to the data source definition. Note that you may also perform a JNDI lookup by looking up the logical name that you defined in the environment of the bean container. You retrieve the database connection using the getConnection method. Using the data source definition, for example, you retrieve a database connection as follows: Context ic = new InitialContext(); Because the data source already contains the username and password attributes, you can use the getConnection method without the username/password attributes.
blog comments powered by Disqus |