Showing posts with label Tomcat. Show all posts
Showing posts with label Tomcat. Show all posts

Monday, November 1, 2010

Connection Pooling in Tomcat6.0

Connection Pooling: is a pool of pre-established connections. Connection Pooling is the art of an Application. A connection with the database is a heavy weight process and if it is not created properly it downs the performance of the Application.

Connection Pooling can be maintained either in Applications level or in Web or Application Server level. Struts and Hibernate frame works are providing Application level Connection Pooling

Connection Pooling is provided by Web Server and Applications Server vendors. Implementation of Connection Pooling is different from Server to Server.

Implementation of Connection Pooling for Oracle 8i, 9i & 10g in Tomcat6.0


1. Copy the below Resource tag in between open tag <Context> and end tag </Context> of context.xml available in Tomcat’s conf directory.
For example
   C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\
<Context>
           <Resource name="jdbc/myoracle" auth="Container"
              type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
              username="scott" password="tiger" maxActive="20" maxIdle="10"
              maxWait="-1"/>          
</Context>

2. You can have any number of Resource tags as you wish but names must be different.

3. Copy the below tag in web.xml in WEB-INF available in your Web Project
<web-app>
    <resource-ref>
    <description>Oracle Datasource example</description>
    <res-ref-name>jdbc/myoracle</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </web-app>
 
  Copy the ojdbc14.jar in Tomcat’s lib directory say
  C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib
  
4. Create a Java Class ConnectionPooling
 
import java.sql.Connection;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConnectionPooling {
    private static DataSource ds;
public static Connection getDBConnection() throws NamingException {
Connection con =null;
    try {
  
if( ds!=null)
{
con =ds.getConnection();
}else
{
 Context initContext = new InitialContext();
    Context envContext = (Context)       initContext.lookup("java:/comp/env");
    DataSource ds = (DataSource) envContext.lookup("jdbc/myoracle");
    con = ds.getConnection();
}   
} catch (Exception e) {
    e.printStackTrace();
    }
    return con;
    }
}


Now Connection pooling has been setup now  test your application using this connection pooling.

Sunday, August 22, 2010

Deploying a war file(project) in Tomcat web server in Windows

Steps for Deploying a project in Tomcat web server in Windows

1.Open the NetBeans IDE
2.Open the project
3.Right click on the project in projects tab
4.Click on the 'clean and build' option
5.Click on 'Deploy' option
6.Now go to folder where your project is reside in your system
say D:\projects\nameoftheproject\dist folder
7.You can find the nameoftheproject.war file in dist folder
8.Open the tomcat foder in your system say c:\program files\ApacheSoftwareFoundation\Tomcat6.0
9.Open the logs folder
10.Delete all the log files which are present upto now
11.Open the work folder--->catalina--->localhost
12.Delete all the folders(all these folders are temporary folders created by the tomcat)
13.Open the webapps folder
14.Delete the war file and project folder(if it is already present, before this you need to stop the tomcat server)
15.Copy the war file and paste in the c:\program files\ApacheSoftwareFoundation\Tomcat6.0\webapps folder
16.Run the project in the firefox with appropriate url say:http://localhost:8080/nameoftheproject

JSF Related topics: JCaptcha in JSF, Integrating Richfaces with JSF,Getting client and server sessionId in JSF,PopUp AlertMessagebox for JSF and more.....

Friday, August 20, 2010

Configuring tomcat in windows

Download 32-bit Windows zip file which is binary flavour of apache tomcat

This flavour comes in zip file, which runs on on both 32 and 64 bit Windows platforms
Extract the zip file, now you will get apache tomcat software

Where you can find startup.bat and shutdown.bat files in apache-tomcat-6.0.26\bin folder

Copy the downloaded apache tomcat folder and paste in appropriate folder say c:\program files

Now configure the apache tomcat in Environment Variables

Right click on the My Computer icon

Go to Advanced---> Environment Variables

In System Variables create a new system variable called CATALINA_HOME and value is c:\program files\apache-tomcat-6.0.26

In System Variables select path variable and click on Edit button and append the following one

%CATALINA_HOME%\bin;

if you want to run apache tomcat as a service in windows

download 32-bit/64-bit Windows Service Installer

after downloading you can see a .exe file

by clicking on that file you can install apache tomcat in your system

while installing it asks you for full or custom installation, choose depends on your requirement

and after it asks you java path which is installed on your system

Note: java software is mandatory to run the apache tomcat

and after installing successfully configure in Environment Variables