title: HOW TO SOLVE Servlet execution threw an exception?
body: <p>I Have been doing a project for uploading files using jsp, servlets and tomcat.</p>
  
  <p>But, i have been getting the following error:</p>
  
  <pre><code>type Exception report
  
  message Servlet execution threw an exception
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  javax.servlet.ServletException: Servlet execution threw an exception
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  root cause
  
  java.lang.NoClassDefFoundError: database/Db_Connection
      controller.UploadFileController.doPost(UploadFileController.java:52)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  note The full stack trace of the root cause is available in the Apache Tomcat/8.0.24 logs.
  </code></pre>
  
  <p>My servlet code is:</p>
  
  <pre><code>        package controller;
  
          import java.io.IOException;
          import java.io.InputStream;
          import java.sql.Connection;
          import java.sql.PreparedStatement;
          import javax.servlet.ServletException;
          import javax.servlet.annotation.MultipartConfig;
          import javax.servlet.annotation.WebServlet;
          import javax.servlet.http.HttpServlet;
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;
          import javax.servlet.http.Part;
          import database.Db_Connection;
          import java.io.PrintWriter;
          import java.util.Random;
          import javax.servlet.RequestDispatcher;
  
          @WebServlet("/uploadServlet")
          @MultipartConfig(maxFileSize = 16177215)
  
          public class UploadFileController extends HttpServlet 
        {
         @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException 
      {
                  response.setContentType("text/html;charset=UTF-8");
                  PrintWriter out = response.getWriter();
  
                  InputStream inputStream = null;
  
                  Random rand = new Random();
                  int  n = rand.nextInt(9999) + 1;
                  String idTemp=(String.valueOf(n));
  
  
                  String title=(request.getParameter("title"));
                  Part filePart = request.getPart("file_uploaded");
  
                  if (filePart != null) 
                  {
                      System.out.println(filePart.getName());
                      System.out.println(filePart.getSize());
                      System.out.println(filePart.getContentType());
  
                      inputStream = filePart.getInputStream();
                  }
  
                  try 
                  {
                      Db_Connection dbconn=new Db_Connection();
                      Connection conn= dbconn.Connection();
  
                      String sql = "INSERT INTO files (id, title, file1) values (?, ?, ?)";
                      PreparedStatement statement = conn.prepareStatement(sql);
                      statement.setString(1, idTemp);
                      statement.setString(2, title);
  
                      if (inputStream != null) 
                      {
                          statement.setBinaryStream(3, inputStream, (int) filePart.getSize());
                      }
  
                      int row = statement.executeUpdate();
                      if (row &gt; 0) 
                      {
                          out.println("File uploaded!!!");
  
                          conn.close();
  
                          RequestDispatcher rs = request.getRequestDispatcher("upload_form.jsp");
                          rs.include(request, response);
                      }
                      else
                      {
                          out.println("Couldn't upload your file!!!");
  
                          conn.close();
  
                          RequestDispatcher rs = request.getRequestDispatcher("upload_form.jsp");
                          rs.include(request, response);
                      }    
  
                  }catch(Exception e){e.printStackTrace();}     
      }   
  }
  </code></pre>
  
  <p>We have created a database in oracle 10g using the following</p>
  
  <pre><code>   create table files(id number(10), title varchar(20),file1 varchar(20));
  </code></pre>
  
  <p>The files we are trying to upload is of size 5 bytes.I have done the database connection also. Could you please help me resolve this error.</p>