In this tutorial we are going to learn how we can insert a value from a html form in the table stored in the database.
For inserting the values in the database table it is required to have a table in which we are going to insert the values. Now make one jsp page or html page where we will insert the values. In this program we have made one simple enquiry form which will get stored in the database table and when the data gets entered into the database then you will get a message. Make one submit button for inserting the values into the database. Firstly this values will go to the controller and retrieved the variables enter in the form by the method getParameter() method of the request object. Pass a query to insert the values retrieved from the html form. To set the values into the database use setString() method. To retrieve the values from the database use getString() method of the PreparedStatement object.
The code of the program is given below:
<html>
|
ServletUserEnquiryForm.java
import java.io.*;
|
web.xml file for this program:
<?xml version="1.0" encoding="ISO-8859-1"?>
|
The output of the program is given below:
Login.html form for the data input:
![]() |
The output of the input data:
![]() |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: insert into statement in sql using servlets View All Comments
Post your Comment