Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

compilation error during connection servlet to oracle

Posted on 2002-03-25
4
Medium Priority
?
254 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 100 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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 …
A solution for Fortify Path Manipulation.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses

722 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