Step 1: To configure a Oracle DataSource, you first have to define a Oracle
JDBC Provider. Open the application server administrative console and
from the left-hand panel, choose Resources>JDBC Providers
Step:2 Choose New to specify a new JDBC provider.
Step 3: Select the database type as oracle, specify a provider type
as Oracle JDBC Driver,implementation type as Connection pool data source
and name is user defined name then click Next.
Step 4: Specify the path of the ojdbc6.jar or ojdbc14.jar file then click Next.
Step 5: In the next step u can see the summary of actions then click finish.
Step 6: Set Up the J2C Authentication Data
From the left-hand panel, choose Security>Global Security.
Step 7:
In the Configuration screen, under the Authentication section
in the right column, expand the JAAS Configuration option, and choose
the J2C Authentication data option.
Step 8:
In the J2C dialog, click the New button to create a new
authentication data entry. Next step in the General Properties Alian
name u can give any name, in the User Id give your oracle database user
id and in the password give your oracle database password and then click
apply and ok.
Step 9:
For creating Oracle Data Source from the left-hand panel,
choose Resources>Data Sources.Choose New to specify a new Data
Source, In the data source name option give any name and in the JNDI
name give any name and then click next
Step 10:
Under the Select JDBC provider select the Select an existing
JDBC provider button in that you select the option of what you have
mentioned in the JDBC Provider and then click next.
Step 11:
Here you should enter the URL of the oracle
database(jdbc:oracle:thin:@localhost:1521:XE) and in the data store
helper class name option select the version of the Oracle database what
you have installed in your system and then click next
Step 12:
For security aliases select the Component-managed
authentication alias and Container-managed authentication alias and then
click next
Step 13:
Here you can see the summary of actions and then click finish.
Step 14:
For test the Connection select name and click on Test
connection button, in the same page up you can see the message like
connection successful.
Steps for using the Oracle DataSource in your J2EE Application
1). In web.xml file we have to write like
<resource-ref>
<description>Datasource connection to db</description>
<res-ref-name>jdbc/dbc</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
</resource-ref>
Here our Jndi name is SatyamSoft_Jndi. This name we should write
in ibm-web-bnd.xml file in the <resource-ref> tag under the
binding-name attribute and in the application DataSource dataSource =
(DataSource)context.lookup("SatyamSoft_Jndi").
2). In ibm-web-bnd.xml file we have to write like
<virtual-ref name="default_host"/>
<resource-ref name="jdbc/dbc" binding-name="SatyamSoft_Jndi"/>
3). In your application mainly you should import the
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.io.*;
import javax.sql.*;
4). Actually for getting database connection object we are mentioning
the Driver name,URL,Username,Password. But now we can write like below
- Context context = new InitialContext();
- DataSource dataSource = (DataSource)context.lookup("SatyamSoft_Jndi");
- Connection conn = dataSource.getConnection();
After getting Connection Object we can retrive,insert update and delete the data Using the Oracle Database.
For Download ScreenShots Click here
No comments:
Post a Comment