You need some basic understanding of JDBC (Java Data Base Connectivity) and Servlet. There are tons of way to achieve what you want, but below is a minimal example to give you some idea:
1. Create a servlet to handle the user input and insert the data into SQL
package mycoolapp;
public RegistrationServlet extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
// Obtain submitted form data
String name = req.getParameterName("Name");
String address = req.getParameterName("Address");
String phone = req.getParameterName("Phone");
String email = req.getParameterName("Email");
// Setup your database datasource, this is different for each db vendor. On production environment most likely you need a connection pooled datasource
DataSource ds = // setup ds here..
Connection conn = ds.getConnection();
// Prepare the SQL statement to insert, plug in the values
PreparedStatement stmt = conn.prepareStatement("INSERT INTO people (fullName, address, telephone, email) VALUES (?, ?, ?, ?)");
stmt.setString(1, name);
stmt.setString(2, address);
stmt.setString(3, phone);
stmt.setString(4, email);
// Execute the insert
stmt.executeUpdate();
conn.close();
// Dispatch into success page
RequestDispatcher requestDispatcher = req.getRequestDispatcher("/registerSuccess.jsp");
requestDispatcher.forward(req, res);
}
}
2. Declare and map the servlet on your WEB-INF/web.xml deployment descriptor
Below setting will map the servlet into http://myhost/mywarname/register
<web-app>
<servlet>
<servlet-class>mycoolapp.RegistrationServlet</servlet-class>
<servlet-name>RegistrationServlet</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
</web-app>
3. Configure your form to post into the servlet
<form method="post" action="register">
....
</form>
Few words of warning:
- Servlet code above does not come with appropriate exception and error handling
- JDBC code above does not come with appropriate transaction management
- The above example is by no mean the industry standard best practice, it is in fact an old & obsolete approach. It shows the fundamental how java servlets and database interaction works. When you're building a proper application, consider using web framework such as Spring, JSF or others.