How to use JSP+MySQL to create a guestbook (1)
Author:Eve Cole
Update Time:2009-07-02 17:13:21
Note: To create a guestbook using JSP+MySQL database, you must first create a MySQL database. For information on the use of MySQL, please go to http://pinghui.51.net/download/012mysql.chm to download the tutorial. Now for the sake of explanation, we assume that the database has been created. The name of the database is pinghui, and there is a comment table to record message information.
The structure of the database is:
+----------+-------------+------+-----+---------- ----------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------- ----------+----------------+
| userid | int(11) | | PRI | 0 | auto_increment |
| username | char(20) | | | | |
| sex | char(2) | | | | |
| address | char(40) | YES | | NULL | |
| ip | char(15) | | | | |
| post | int(11) | YES | | 0 | |
| oicq | int(11) | YES | | 0 | |
| icq | int(11) | YES | | 0 | |
| telnumber | char(30) | YES | | NULL | |
| comment | text | | | NULL | |
| time | datetime | | | 0000-00-00 00:00:00 | |
+----------+-------------+------+-----+---------- ----------+----------------+
If you think creating a database is too troublesome, the statement to create a database is:
DROP DATABASE IF EXISTS pinghui;
CREATE DATABASE pinghui;
USEpinghui;
CREATE TABLE comment(
userid int NOT NULL DEFAULT 0 AUTO_INCREMENT PRIMARY KEY,
username char(20) NOT NULL,
sex char(2),
address char(40),
ip char(15) NOT NULL,
post int DEFAULT 0,
oicq int DEFAULT 0,
icq int DEFAULT 0,
telnumber char(30),
comment text NOT NULL,
time datetime NOT NULL
);
INSERT INTO comment (username,ip,comment,time) VALUES ("pinghui","127.0.0.1",
"Hello, please go to Pinghui Free Space to view information!",now());
insert into comment (username,sex,address,ip,post,oicq,icq,telnumber,comment,time)
values ('pinghui','male','address','127.0.0.1',250100,2269101,74875874,'0531-8605449',
'Hello, please go to Pinghui Free Space to check the message! Thanks! ',now());
With the database, our explanation below will be more convenient. Continue to create the guestbook