package Agents;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "InsertAgents", urlPatterns = {"/InsertAgents"})


public class InsertAgents extends HttpServlet {



protected void doPOST(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");          


    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Insert Agents</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>RRE Agents</h1>");
         out.write("\n");
  out.write("        <form name=\"RRE Agents\" action=\"AGENTS\" method=\"post\"");
  out.write("            <table border=\"0\">\n");
  out.write("                <tbody>\n");
  out.write("                    <tr>\n");
  out.write("                       <td>Agent ID: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"AGENT_ID\" value=\"\" size=\"50\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                        <td>Title: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"TITLE\" value=\"\" size=\"50\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                    <tr>\n");
  out.write("                        <td>First Name: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"FIRST_NAME\" value=\"\" size=\"50\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                    <tr>\n");
  out.write("                        <td>Middle Name: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"MIDDLE_NAME\" value=\"\" size=\"10\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                    <tr>\n");
  out.write("                        <td>Last Name: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"LAST_NAME\" value=\"\" size=\"50\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                    <tr>\n");
  out.write("                        <td>Cell Phone: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"CELL_PHONE\" value=\"\" size=\"10\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                    <tr>\n");
  out.write("                        <td>Pager: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"PAGER\" value=\"\" size=\"10\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                    <tr>\n");
  out.write("                        <td>Home Phone: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"HOME_PHONE\" value=\"\" size=\"10\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                    <tr>\n");
  out.write("                        <td>Office Phone: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"OFFICE_PHONE\" value=\"\" size=\"10\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                    <tr>\n");
  out.write("                        <td>Hire Date: </td>\n");
  out.write("                        <td><input type=\"text\" name=\"HIRE_DATE\" value=\"\" size=\"25\" /></td>\n");
  out.write("                    </tr>\n");
  out.write("                </tbody>\n");
  out.write("            </table>\n");
  out.write("</br>");
  out.write("<input type = 'reset' value = 'clear' name = 'clear' />");
  out.write("<input type = 'reset' value = 'submit' name = 'submit' />");


            // register driver
    try {
         //Class.forName("oracle.jdbc.driver.OracleDriver"); // Oracle's thin driver
        Class.forName("oracle.jdbc.driver.OracleDriver"); // Sun's JDBC/ODBC bridge driver

        // connect to DB
        try {
            Connection con = DriverManager.getConnection(
                                "jdbc:oracle:thin:@//fa14-cmis440-485:1521/CITEDB", // JDBC/ODBC bridge driver
                                //"jdbc:odbc:oraodbc",
                                "jdillinger2",
                                "truel0v3");
        }
                        catch(Exception ex) 
        {
            out.println("Error performing DB connection: " + ex);
            return;
        }

} 
    catch(Exception ex) 
    {
        out.println("Can't load driver: " + ex);
        return;
    }

   out.write("</form>");      

        out.println("</body>");
        out.println("</html>");

    }
}



// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doPOST(request, response);
}

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doPOST(request, response);
}



}

I cannot get the information that I fill out in the form to store into my sql database. The code above is a servlet titled InsertAgents.java and I have a main index.html file and that links the Agents.html and then I can access the servlet and fill out the form, but the information does not store to my database. I inserted my database into the DB connections within netbeans, and uploaded the driver as necessary, but the information will not store and I am not receiving erros. Any advice will be greatly appreciated.

well, you're creating a connection to the database and then doing nothing with that connection.
Small wonder then that nothing is getting stored...

btw, why are you coding this this way? That's how things were done 15 years ago, the world has moved on since then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.