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 Crazy on the Outside Online Free
  • Watch It’s Complicated Full Video Online
  • Watch Leap Year Free Stream Online
  • Watch Manchester United vs Birmingham Live Stream
  • Watch Avatar Online Stream
  • Watch Nine Online Video
  • Watch Crazy Heart Full Stream
  • Modern Family Season 1 Episode 11 | Watch Modern Family s01e11 Up All Night Full Episode
  • Burnley vs Arsenal EPL | Watch Burnley vs Arsenal Live Stream
  • Watch The Princess and the Frog Online Free

Warning: include(adbottom.html) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/iwebie.com/httpdocs/wp-content/themes/iWebie/rightsidebar.php on line 20

Warning: include() [function.include]: Failed opening 'adbottom.html' for inclusion (include_path='.:/opt/lsws/lsphp5/lib/php') in /var/www/vhosts/iwebie.com/httpdocs/wp-content/themes/iWebie/rightsidebar.php on line 20
Archives

  • January 2010
  • December 2009
  • 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