Solved

compilation error during connection servlet to oracle

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

765 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