Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7546959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:19:58+00:00 2026-05-30T09:19:58+00:00

I am trying a servlet that puts the data into the database:derbi (that comes

  • 0

I am trying a servlet that puts the data into the database:derbi (that comes packed with netbeans). When a user clicks to submit data,the request follows to the FormHandler servlet (given below) If any of the text-field was empty the request follows to another servlet ErrorServlet and if every thing was fine the request follows to the Registered servlet. But before the request follows to the Registered Servlet there is a small code that is written to insert the data into the database (After this code the the user views the success page,that he has been registered).

Now the problem : The user fills all the text fields in the form and clicks submit. When he clicks submit,he sees the success page displaying Registered Successfully . But when i query the databse, i see that the data wasn’t submitted to the databse. The rows and columns are empty ! I don’t understand the reason for this .

Code for FormHandler.java :

package FormHandler;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.LinkedList;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class FormHandler extends HttpServlet {
  @Override
         public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
    
}

@Override
        public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
    
    String name = request.getParameter("Name");
    String email = request.getParameter("Email");
    String password = request.getParameter("Password");
    
    LinkedList list = new LinkedList();
    
    if(name.compareTo("") == 0 || email.compareTo("") == 0 || email.compareTo("") == 0) {
        list.add("One or more field's' left blank");
        request.setAttribute("ErrorList", list);
        RequestDispatcher rd = request.getRequestDispatcher("ErrorServlet.view");
        rd.forward(request, response);
    } else {
        try {
            Context context = new InitialContext();
            DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/MyDatasource");
            Connection connection = ds.getConnection();
           String sqlStatement = "INSERT INTO INFORMATION VALUES('" + name + "'," + "'" + email + "'," + "'" + password + "')";  
               PreparedStatement statement = connection.prepareStatement(sqlStatement);
               ResultSet result = statement.executeQuery();     
        }catch(Exception exc) {
            System.out.println(exc);
        }
        request.setAttribute("Data", list);
        RequestDispatcher rd = request.getRequestDispatcher("Registered.view");
        rd.forward(request, response);
      }
    
    
}

}

XML file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
    <servlet-name>FormHandler</servlet-name>
    <servlet-class>FormHandler.FormHandler</servlet-class>
</servlet>
<servlet>
    <servlet-name>Registered</servlet-name>
    <servlet-class>FormHandler.Registered</servlet-class>
</servlet>
<servlet>
    <servlet-name>ErrorServlet</servlet-name>
    <servlet-class>FormHandler.ErrorServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>FormHandler</servlet-name>
    <url-pattern>/FormHandler.do</url-pattern>
</servlet-mapping>

<resource-ref>
    <res-ref-name>jdbc/MyDatasource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

<servlet-mapping>
    <servlet-name>Registered</servlet-name>
    <url-pattern>/Registered.view</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>ErrorServlet</servlet-name>
    <url-pattern>/ErrorServlet.view</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

Html File :Code for html file

Note : I have already made a connection to database

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:19:59+00:00Added an answer on May 30, 2026 at 9:19 am

    I think you are getting somewhere a :

     java.sql.SQLException: No ResultSet was produced
    

    because executing your UPDATE query with executeQuery() actually returns no resultset

    Use:

     statement.executeUpdate();     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue with a servlet that delivers multimedia data. I'm trying to
I am trying to write a servlet that will send a XML file (xml
I am trying to dispatch in a servlet request handler to the JSP processor
I'm trying to tracking valid user Ids in my Java servlet, can I implement
I have a servlet that needs to write out files that have a user-configurable
When trying to pass a table built with HTML in my servlet like that:
How can I detect that the client side of a tomcat servlet request has
I am trying to build a servlet that parses form input and creates a
I have a servlet that does a request dispatcher include of another servlet. The
I am trying to complete the tutorial at http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=438 It seems that the servlet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.