|
|
We've seen a select query. Now lets' make an insert query and select
the results after we've inserted.
Steps:
-
On the command line, run mysqld and mysql.
-
Create two tables (if you haven't already):
-
Students: Name, BearcatID, Major, Gender, CollegeID
-
Colleges: Name, Dean, CollegeID
-
Make sure you choose the best data types.
-
Don't worry about primary key constraints, null values, etc.
-
Pre-populate the Colleges table with some data. You may populate
students if you want to as well.
-
Make a JSP similar to the example.
Run it to make sure you have a connection.
-
Write a JSP entry page.
-
Include fields for the columns in students.
-
Have it call your select JSP.
-
In the select JSP, put in some logic to insert a row into the database
given the values sent from the entry JSP. Preferrably do this before
your select, so that you can verify that the insert happened.
-
use request.getParameter("field name"); to get the data
passed from the input form.
-
If you have time, get wild and crazy.
-
Have your select join the students and colleges tables.
-
Pre-populate a drop down on the entry page with college IDs or colleges.
-
Here's what I came up with. If you get stuck, take a look.
|