Installation Steps
- Install java 1.7
- Download and extract Apache-Tomcat zip to any loacation
- Define JAVA_HOME environment variable to java 1.7
- Download ojdbc5.jar to Apache-Tomcat\lib folder
- Place any supporting java classes in WEB-INF\classes directory
- run startup.bat file
- Invoke jsp from browser
- Go to conf folder-> tomcat-users.xml
- Add role "manager-gui" role using following xml tag
<role rolename="manager-gui"/> - add user with the "manager-gui" role using following xml tag
<user username="admin" password="admin" roles="manager-gui"/> - Remove unwanted users from the list
- Restart server
- Download jdbc driver jar file
- Place it in WEB-INF/lib directory
- Define connection pool in WebContent/META-INF/context.xml
- <Context>
<Resource name="jdbc/bugap_db"
auth="Container" type="javax.sql.DataSource"
maxActive="10" maxIdle="1" maxWait="10000"
username="vdesu" password="asdf321"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SLC03RYC.us.oracle.com)(PORT=1521)) (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xe)))"/>
</Context> - Define resource reference in WEB-INF/web.xml
- <resource-ref>
<description>BugDB Connection Pooling</description>
<res-ref-name>jdbc/bugap_db </res-ref-name>
<res-type> javax.sql.DataSource</res-type>
<res-auth> Container</res-auth>
</resource-ref> - Get connection pool reference in java code
- Using Java Naming and Directory Interface
public Connection getConnection() {
Connection connection = null;
try {
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB");
connection = ds.getConnection();
}
catch (Exception e) {
System.out.println("Connection error: " + e.getMessage());
}
return connection;
}- Resourcing injection with servlets
@Resource(name="jdbc/bugap_db")
private DataSource dataSource;
No comments:
Post a Comment