Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By doWhile

Thread: entering servlet form values into database

  1. #1
    mallikanala is offline Member
    Join Date
    Jun 2011
    Posts
    10
    Rep Power
    0

    Default entering servlet form values into database

    how can i get servlet form data into database?. please modify my code and send it.
    I m sending with my requirements
    ..................................
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String Name = request.getParameter("name");
    String Age = request.getParameter("age");
    String Gender = request.getParameter("gender");
    String Origin= request.getParameter("origin");
    String Destination = request.getParameter("destination");
    boolean resStatus=false;
    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();

    }

    Connection con=null;
    Statement stmt=null;
    ResultSet rs=null;
    try
    {
    con=DriverManager.getConnection("jdbc:oracle:thin: @localhost:1521:XE","system","malli");
    stmt=con.createStatement();
    String sql="insert into RESERVATION_DETAILS values('+Name+','+Age+',+Gender+','+Origin+','+Des tination+')";
    rs=stmt.executeQuery(sql);
    resStatus=rs.next();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    finally
    {
    try
    {
    if(rs!=null)
    {
    rs.close();
    rs=null;
    }
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }


    try
    {
    if(stmt!=null)
    {
    stmt.close();
    stmt=null;
    }
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();

    }
    try
    {
    if(con!=null)
    {
    con.close();
    con=null;
    }
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }


    PrintWriter out=response.getWriter();
    if(resStatus)
    {
    out.println("reservation success");
    }
    else
    {
    out.println("registration fail");
    }
    out.println("<a href='http://localhost:7070/proj_dev_resv/LoginServlet?username=malli&password=123'>back</a>");
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    how can i get servlet form data into database?. please modify my code and send it.
    Sorry, it doesn't work that way. I suggest you modify your own code, make an effort, and should you get stuck ask a specific question.
    Fubarable likes this.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    And in that spirit...
    What errors are you getting?
    Complete errors, not your interpretation of them...with stack traces if they are runtime exceptions.

    And please use code tags when posting code.

Similar Threads

  1. entering textfile into database
    By UJJAL DHAR in forum New To Java
    Replies: 11
    Last Post: 06-15-2010, 01:55 AM
  2. Replies: 0
    Last Post: 10-31-2009, 09:24 AM
  3. how can i link html+servlet+xml to form servlet
    By balachandarr in forum Java Servlet
    Replies: 0
    Last Post: 04-15-2009, 04:06 PM
  4. Replies: 1
    Last Post: 03-19-2009, 07:38 AM
  5. Getting HTML form values in Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-17-2007, 08:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •