Servlets Database Access - Java Servlets

What is Servlets Database Access?

This lesson assumes you have understanding on how JDBC application works. Formerly starting with database entrance through a servlet, make sure you have good JDBC environment setup along with a database.

For more detail on how to access database using JDBC and its environment setup you can go through our JDBC Tutorial

To start with basic idea, let us make a simple table and create few records in that table as follows −

Create Table

To create the Employees table in TEST database, use the following steps −

Step 1
Open a Command Prompt and change to the installation directory as follows –

Step 2
Login to database as follows

Step 3
Create the table Employee in TEST database as follows –

Create Data Records

Finally you create few records in Employee table as follows –

Accessing a Database

Here is an example which shows how to access TEST database using Servlet.

Now let us compile above servlet and create following entries in web.xml

Currently call this servlet using URL http://localhost:8080/DatabaseAccess which would show resulting answer −

Database Result

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Java Servlets Topics