Solved

compilation error during connection servlet to oracle

Posted on 2002-03-25
4
246 Views
Last Modified: 2013-11-24
i compiled this code and it give me an error msg:
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDrive());
                   
showing an arrow toword OracleDrive                      
============================================
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class HowTo_Oracle_Servlet extends HttpServlet
{
   public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
   {
      response.setContentType("Text/html");
      PrintWriter out = response.getWriter();

      out.println("<HTML>");
      out.println("<HEAD><TITLE>Simple Oracle Example</TITLE></HEAD>");
      out.println("<BODY BGCOLOR=\"#FFFFFF\">");
      out.println("<CENTER>");
      out.println("<B>Employees</B>");
      out.println("<BR><BR>");

      Connection conn = null;
      try
      {
         DriverManager.registerDriver(new oracle.jdbc.driver.OracleDrive());                                                                                
             conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","user", "pass");                                                  
                                                                               
         Statement stmt = conn.createStatement();                              
         ResultSet rs = stmt.executeQuery("SELECT * FROM EMPLOYEE");        
                                                                               
         //Print start of table and column headers                              
         out.println("<TABLE CELLSPACING=\"0\" CELLPADDING=\"3\" BORDER=\"1\">");                                                                              
         out.println("<TR><TH>ID</TH><TH>NAME</TH></TR>");                      
                                                                               
         //Loop through results of query.                                      
         while(rs.next())                                                      
         {                                                                      
            out.println("<TR>");                                                              
            out.println("<TD>" + rs.getString("Name") + "</TD>");              
            out.println("</TR>");                                              
         }                                                                      

         out.println("</TABLE>");
      }                                                                        
      catch(SQLException e)                                                    
      {                                                                        
         out.println("SQLException: " + e.getMessage() + "<BR>");              
         while((e = e.getNextException()) != null)                              
            out.println(e.getMessage() + "<BR>");                              
      }                                                                        
                                                                             
      finally                                                                  
      {                                                                        
         //Clean up resources, close the connection.                            
         if(conn != null)                                                      
         {                                                                      
            try                                                                
            {                                                                  
               conn.close();                                                    
            }                                                                  
            catch (Exception ignored) {}                                        
         }                                                                      
      }                                                                        
                                                                               
      out.println("</CENTER>");                                                
      out.println("</BODY>");                                                  
      out.println("</HTML>");                                                  
                                                                               
   }                                                                            
}
=========================================
what is worng with this code and how to fix it.
Before some change it gives me this error in the browser
using servlet runner :

Employees


Error: 500
Internal Servlet Error:

java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver
      at HowTo_Oracle_Servlet.doGet(HowTo_Oracle_Servlet.java:24)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
      at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
      at com.sun.web.core.InvokerServlet.service(InvokerServlet.java:169)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
      at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
      at com.sun.web.core.Context.handleRequest(Context.java:375)
      at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:135)
=================================================
0
Comment
Question by:farsi
4 Comments
 
LVL 4

Accepted Solution

by:
m_onkey_boy earned 25 total points
ID: 6894975
Your runtime classpath is not pointing to the jar with your Oracle drivers.
0
 

Expert Comment

by:abhay_djs
ID: 6898306
Yeah whatever m_onkey_boy  says is correct.
You have to include classes111.zip which provides JDBC connection with oracle in your classpath
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7892573
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: m_onkey_boy
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7962528
Per recommendation, force-accepted.

Netminder
EE Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now