Copy the files ojdbc14dms.jar and dms.jar file in to
C:\Sun\AppServer14\lib directory.
Create a connection pool with the following ,
oracle.jdbc.pool.OracleDataSource
resource type as javax.sql.DataSource
Enter the following fields
Password tiger
User scott
ServiceName ravi.idc.oracle.com
PortNumber 1522
ServerName incq128ad
URL jdbc:oracle:thin:@incq128ad:1522:ravi1
After this create JDBC Resources and name it as jdbc/OracleDS
and select the above connection pool.
Create a War file based on the test.jsp file with the following code ,
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="java.sql.*,oracle.jdbc.driver.*,javax.naming.*,oracle.sql.*,javax.sql.*" %>
<% if (request.getParameter("empID") != null) {
String empID = request.getParameter("empID");
InitialContext testContext = null;
DataSource testOC4JDataSource = null;
Connection testDatabaseConnection = null;
Statement testDatabaseStatement = null;
ResultSet testDatabaseResultSet = null;
try {
testContext = new InitialContext();
testOC4JDataSource = (DataSource) testContext.lookup("jdbc/OracleDS");
testDatabaseConnection = testOC4JDataSource.getConnection();
testDatabaseStatement = testDatabaseConnection.createStatement();
String testQuery = "SELECT * FROM SCOTT.EMP where EMPNO =" + empID;
testDatabaseResultSet = testDatabaseStatement.executeQuery(testQuery);
while (testDatabaseResultSet.next()) {
out.println("
" + testDatabaseResultSet.getString("ENAME"));
}
} catch (Throwable e) {
String err = e.toString();
System.out.println(err);
} finally {
try {
testDatabaseStatement.close();
testDatabaseConnection.close();
} catch ( Throwable e) {
String err = e.toString();
System.out.println(err);
}
}
}
%>
Create the war file in Jdeveloper and deploy the file using the Sun Admin Console
No comments:
Post a Comment