Solved

compilation error during connection servlet to oracle

Posted on 2002-03-25
4
252 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete Android all or certain applications data programmatically 9 153
Desingning Refactoring existing code 2 46
Chrome and Firefox Java 5 89
junit example issue 2 59
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 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