Discussions

Web tier: servlets, JSP, Web frameworks: simple form of inserting values into database..help needed

  1. sup guys..hav a problem here..im trying to make a simple registration form for ppl to type in values and submit to the database..however, the values are not stored inside the table. for more info, im using oracle toad database. can someone tell me the errors im facing? desperate help needed thx...

    APPSFORM.JSP

    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.*" %>


    <html>
    <body>
    <br>
    <center>
             
                <font size="5">For Applicating DepartMent</font>
             
             <form method="post" action="appsdata2.jsp" >
                <table border="0">
                   <tr>
                      <td>Employee's Full name</td>
                      <td>
               <input name="employee_name" value="" size="30"/>
                      </td>
                   </tr>
                   <tr>
                      <td>Employee's number</td>
                      <td>
              <input name="employee_number" value="" size="30"/>
                      </td>
                   </tr>
                   <tr>
                      <td>Department Drive (G):</td>
                      <td>
              <input type="radio" name="dept_drive_flag">Yes
              <input type="radio" name="dept_drive_flag">No
                      </td>
                    
                </table>


    <br>
    <input type="submit" value="Submit"/>
                <input type="reset" value="Clear"/>
             </form>
          </center>
       </body>
    </html>

    APPSDATA.JSP


    <%@ page language="java"%>
    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.*" %>

    <%
      Connection con = null;
      Statement stmt = null;
      ResultSet rs = null;


    String queryText = "insert into ttt values(\"" + request.getParameter("employee_name") + "\",\"" + request.getParameter("employee_number") + "\",\"" + request.getParameter("dept_drive_flag") + "\");";

      try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        con = DriverManager.getConnection("jdbc:oracle:thin:@15.12.88.202:1522:test", "apps", "apps");
        stmt = con.createStatement();
        rs = stmt.executeQuery(querytext);
      } catch (Exception e) {


    %>

    <%@ include file="fail.jsp"%>
      
    <%

      }

      response.sendRedirect("success.jsp");

    %>
  2. Can you post here what error message you are getting?

    Are you able to connect to your database through jsp?

    Is the corresponding data type in your table for 'employee number' an integer or number field? And what value are you passing for 'Department Drive'? If you want to pass the values as 'yes' and 'no', mention that. ie, change into :

    <input type="radio" name="dept_drive_flag" value="Yes">Yes
    <input type="radio" name="dept_drive_flag" value="No">No

    I am not sure if there is any problem with your insert query but try this (assuming that the data type for 'employee number' in your table is a number or integer and that for 'Department Drive' is varchar:

    "insert into ttt values('" + request.getParameter("employee_name") + "'," + request.getParameter("employee_number") + ",'" + request.getParameter("dept_drive_flag") + "')";


    If the 'employee number' field is not a number, then:

    "insert into ttt values('" + request.getParameter("employee_name") + "','" + request.getParameter("employee_number") + "','" + request.getParameter("dept_drive_flag") + "')";

    Hope this helps. If it doesnt, post your error message.
  3. sup guys..
    Do you notice how the 'request' object is in the sql string?
    String queryText = "insert into ttt values(\"" + request.getParameter("employee_name") + "\",\"" + request.getParameter("employee_number") + "\",\"" + request.getParameter("dept_drive_flag") + "\");";
    Sup? That's a kludgey mess, that's what SUP.