title: Querying data from Oracle database using java servlet with Netbeans
body: <p>From index.jsp code, </p>
  
  <pre><code>statement.executeQuery("select * from fus where tester_num like 'hf60' ") ;
  </code></pre>
  
  <p>Example I want "hf60" to be a variable(userinput), wherein USER must input/write  data from input text then submit and get the data so that the result will be </p>
  
  <pre><code>("select  * from fus where tester_num like 'userinput' ")
  </code></pre>
  
  <p>Where should I insert that code, Is it in InsertServlet .java or in Index.jsp.? or make another filename.java code? Please help. Thanks;)</p>
  
  <p><strong>Index.jsp</strong></p>
  
  <pre><code>&lt;%@ page import="java.sql.*" %&gt;
  
  &lt;%  Class.forName("oracle.jdbc.driver.OracleDriver"); %&gt;
  
  &lt;HTML&gt;
  &lt;HEAD&gt;
      &lt;TITLE&gt;SHIFT REPORT &lt;/TITLE&gt;
  &lt;/HEAD&gt;
  
  &lt;BODY BGCOLOR=##342D7E&gt;
      &lt;CENTER&gt;
      &lt;H2&gt;&lt;FONT COLOR="#ECD672" FACE="Verdana" &gt;SHIFT REPORT&lt;/FONT&gt;&lt;/H2&gt;&lt;/CENTER&gt;
  &lt;hr&gt;
      &lt;% 
  
  
   Connection connection=DriverManager.getConnection ("jdbc:oracle:thin:@oradev2.*****.com:1521:RPADB","shift_admin",  //
           "shift_admin"
              );
  
          Statement statement = connection.createStatement() ;
  //**Should I input the codes here?**
          ResultSet resultset = 
              statement.executeQuery("select  * from fus where tester_num like 'hf60") ; 
      %&gt;
  
      &lt;TABLE BORDER="1" BGCOLOR="CCFFFF" width='200%' cellspacing='1' cellpadding='0'   bordercolor="black" border='1'&gt;
          &lt;TR&gt;
              &lt;TH bgcolor='#DAA520'&gt; &lt;font size='2'&gt;RECORD NUMBER&lt;/TH&gt;
              &lt;TH bgcolor='#DAA520'&gt;&lt;font size='2'&gt;TESTER NUMBER&lt;/TH&gt;
              &lt;TH bgcolor='#DAA520'&gt;&lt;font size='2'&gt;DATE&lt;/TH&gt;
              &lt;TH bgcolor='#DAA520'&gt;&lt;font size='2'&gt;TIME&lt;/TH&gt;
              &lt;TH bgcolor='#DAA520'&gt;&lt;font size='2'&gt;SYSTEM TYPE&lt;/TH&gt;
              &lt;TH bgcolor='#DAA520'&gt;&lt;font size='2'&gt;PACKAGE&lt;/TH&gt;
              &lt;TH bgcolor='#DAA520'&gt;&lt;font size='2'&gt;SOCKETS&lt;/TH&gt;
              &lt;TH bgcolor='#DAA520'&gt;&lt;font size='2'&gt;VALIDATED BY&lt;/TH&gt;
          &lt;/TR&gt;
  
          &lt;% while(resultset.next()){ %&gt;
          &lt;TR&gt;
              &lt;TD&gt; &lt;font size='2'&gt;&lt;center&gt;&lt;%= resultset.getLong(1) %&gt;&lt;/center&gt;&lt;/TD&gt;
              &lt;TD&gt; &lt;font size='2'&gt;&lt;center&gt;&lt;%= resultset.getString(2) %&gt;&lt;/center&gt;&lt;/TD&gt;
              &lt;TD&gt; &lt;font size='2'&gt;&lt;center&gt;&lt;%= resultset.getDate(3) %&gt;&lt;/center&gt;&lt;/TD&gt;
              &lt;TD&gt; &lt;font size='2'&gt;&lt;center&gt;&lt;%= resultset.getString(4) %&gt;&lt;/center&gt;&lt;/TD&gt;
              &lt;TD&gt; &lt;font size='2'&gt;&lt;center&gt;&lt;%= resultset.getString(5) %&gt;&lt;/center&gt;&lt;/TD&gt;
              &lt;TD&gt; &lt;font size='2'&gt;&lt;center&gt;&lt;%= resultset.getString(6) %&gt;&lt;/center&gt;&lt;/TD&gt;
              &lt;TD&gt; &lt;font size='2'&gt;&lt;center&gt;&lt;%= resultset.getString(7) %&gt;&lt;/center&gt;&lt;/TD&gt;
              &lt;TD&gt; &lt;font size='2'&gt;&lt;center&gt;&lt;%= resultset.getString(8) %&gt;&lt;/center&gt;&lt;/TD&gt;
              &lt;/TR&gt;
  
          &lt;% } %&gt;
  
      &lt;/TABLE&gt;     
          &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p><strong>InsertServlet.java</strong></p>
  
  <pre><code>package fusion.shift.servlets.db;
  
  import java.sql.*;
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  public class InsertServlet extends HttpServlet {
  
  
  public void init(ServletConfig config) throws ServletException { 
      super.init(config); 
  } 
  
  public void destroy() { 
  } 
  public boolean processRequest(HttpServletRequest request, HttpServletResponse    response) throws ServletException, IOException{
  
  
              String rec_num = request.getParameter("rec_num");
              String tester_num = request.getParameter("tester_num");
              String t_date = request.getParameter("t_date");
              String t_time = request.getParameter("t_time");
              String sys_type = request.getParameter("sys_type");
              String packages = request.getParameter("package");
              String sockets = request.getParameter("sockets");
              String sockets = request.getParameter("val");
  
  
      Connection con = null;
      Statement stmt = null;
      ResultSet rs = null;
      PreparedStatement ps = null;
  
      try {
                   Class.forName("oracle.jdbc.driver.OracleDriver");
      con=DriverManager.getConnection("jdbc:oracle:thin:@oradev2.*****.com:1521:RPADB","shift_admin",  //
           "shift_admin"
              );
  
  
          String sql;
                      sql = "INSERT INTO fusion_shiftrpt(RECORD_NUM, TESTER_NUM, T_DATE, T_TIME, SYSTEM_TYPE, PACKAGE, SOCKETS,VAL) VALUES (?,?,?,?,?,?,?,?)";
  
              ps = con.prepareStatement(sql);
          stmt = con.createStatement();
  
                 ps.setString(1, rec_num);
               .0+  ps.setString(2, tester_num);
                               ps.setString(3, t_date);
                               ps.setString(4, t_time);
                               ps.setString(5, sys_type);
                               ps.setString(6, packages);
                               ps.setString(7, sockets);
                               ps.setString(8, val);
                               ps.executeUpdate();
  
          } catch (SQLException e) {
          throw new ServletException(e);
      } catch (ClassNotFoundException e) {
          throw new ServletException(e);
      } finally {
          try {
              if(rs != null)
                  rs.close();
              if(stmt != null)
                  stmt.close();
              if(ps != null)
                  ps.close();
              if(con != null)
                  con.close();
          } catch (SQLException e) {}
      }
  
   return(true);
   }
  
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException {
          processRequest(request,response);     
  
  }
  protected void doPost(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException {
   processRequest(request,response);
   //String url = request.getRequestURI();
   //System.out.println(url);
  
  }
   }
  </code></pre>