Solved

compilation error during connection servlet to oracle

Posted on 2002-03-25
4
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

634 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