iwebie
HOME MOVIES TV SHOWS SPORTS GENERAL
 RSSPRIVACY
 

Oracle JDBC Connection Tomcat 5.5
Posted by admin on October 6th, 2008

Watch over 100,000 movies and TV shows on your PC

How to Setup or Configure Oracle JDBC Connection with Tomcat 5.5

Below are 3 Steps to Create a JDBC Connection for Tomcat using Oracle driver

Step 1: Copy The Necessary Jars

To begin with You need to copy the Jars namely classes12.jar and classes111.jar from your Oracle Installation to your Tomcat 5.5 Common Lib Folder.

Oracle 9i Path to the Jars

Tomcat 5.5 Path to where the Jars need to be copied

Step 2: Modify the Server.xml file

[sourcecode language='xml']
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
[/sourcecode]

Add the Below peice of code in your Server.xml file just after the closing Tag of the above shown Section;

[sourcecode language='xml']

type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:bob"
username="scott" password="tiger" maxActive="20" maxIdle="10"
maxWait="-1"/>
[/sourcecode]

In the URL, “jdbc:oracle:thin:@127.0.0.1:1521:bob” (url=”jdbc:oracle:thin:@<host>:<port>:<sid>”);

127.0.0.1 is the hostname
1521 is the Port
and bob is the SID

Your Server.xml should look like this


Step 3: Test the Connection Class with the Servlet Code Example as Shown Below.

[sourcecode language='java']
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestConnection extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
Class.forName(”oracle.jdbc.driver.OracleDriver”);

Connection con = DriverManager.getConnection(
“jdbc:oracle:thin:@localhost:1521:bob”, “scott”, “tiger”);
// @machineName:port:SID,   userid,  password

out.println(”“);
out.println(”“);
out.println(”Test JDBC Connection“);
out.println(”“);
out.println(”“);
out.println(”

Connection Established Successfully

“);
out.println(”“);
out.println(”“);

} catch (ClassNotFoundException e1) {
out.println(”Connection Failed ” + e1.toString());
} catch (SQLException e2) {
out.println(”Connection Failed  ” + e2.toString());
} catch (Exception e3) {
out.println(”Connection Failed  ” + e3.toString());
}
}

}
[/sourcecode]

If all is well the Output should look like this;

Bookmark Article
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Propeller

Leave a Reply

Most Popular

Watch over 100,000 movies and TV shows on your PC
Recent Posts

  • Watch Dexter Season 4 Episode 9 | Dexter Hungry Man Online Video
  • Californication Season 3 Episode 9 | Watch Mr. Bad Example Full Episode
  • Watch The Amazing Race Season 15 Episode 9 | The Amazing Race s15e09 Full Video
  • English Premier League | Watch Aston Villa vs Burnley Streaming Live
  • Stargate Universe Season 1 Episode 9 | Watch Stargate Universe s01e09 Life Video Online
  • Smallville Season 9 Episode 9 | Watch Smallville s09e09 Pandora Online Free
  • Monk Season 8 Episode 14 | Watch Mr. Monk and the Badge Streaming Video
  • Community Episode 10 | Watch Community s01e10 Environmental Science Stream Online
  • Watch It’s Always Sunny in Philadelphia Season 5 Episode 10 Full Episode
  • Survivor: Samoa Episode 10 | Watch Survivor s19e10 The Day of Reckoning Free Online
Archives

  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
Powered by WordPress