Servlet deleting updating searching a row from table
The first thing we'll need is an example My SQL database table to work with.
To keep it simple -- but also show several different data types -- I created the following My SQL database table: create table users ( id int unsigned auto_increment not null, first_name varchar(32) not null, last_name varchar(32) not null, date_created timestamp default now(), is_admin boolean, num_points int, primary key (id) ); A few of these fields are a little contrived, but I wanted to show several different data types in one table, so this is what I came up with.
Run the application to make sure it works correctly.
Given that My SQL database table, let's assume that we just want to delete one record in this table. Prepared Statement; /** * A Java My SQL DELETE example.
Note that the Update and Delete links request the Users Servlet and pass an action parameter to it to specify the action and an email address to specify the user.
Open the Users Servlet class and add code for the display_user action that gets the User object for the specified email, stores this object in the request, and forwards the request to the 10.
Review the code Download and open the project named ch12_user Admin. Note that the Users Servlet and User DB classes aren’t finished.
Review the configuration files for this application. Add code to display the users Open the User DB class that’s located in the package.