Application of database operation in JavaServer Pages+javabeans
The above has said a simple JavaBean application of the counter example, of course, in the actual program process, involves more and database-related operations, so in this section we will focus on JavaServer pages and JavaBeans How to operate the database. Here we have selected a more representative and practical example, that is the user registration management, because this is used on the Internet more frequently, whether it is registered email, award-winning survey, purchase items or join the community, etc. will involve a user registration problem; On the other hand, it is more representative, Related to the database record increase, record display and other common operations, so we take the user registration surgery.
The program uses the Oracle Jdeveloper3.1 development, the operating environment is wiin2000+tomcat3.1, the database system uses the oracle8.16i.
First we set up a database Demodb, and the fields are as shown below
Username VARCHAR2 (20) User name
Password VARCHAR2 (20) password
Email VARCHAR2 (email address)
Homepage VARCHAR2 (50) Home
Signs VARCHAR2 (200) signature
Regtime Date Registration Time
Then we build several JavaBeans and JavaServer pages files
Db.java files (encapsulates database connections and some underlying operations)
Adduser.java files (for user data reading and adding operations)
newuser.jsp file (user new page, for entering user registration information)
donewuser.jsp files (add for user registration information)
listuser.jsp file (all registered user Information list)
In order to facilitate everyone to see the code, in many places have been detailed comments and explanations, as for JavaBean in the Java grammar structure of things, please refer to Java books.
Db.java file
Description: This JavaBean encapsulates database connections and some underlying operations, derived classes can call these methods directly, and provides a Tochinese method, which is mainly used for processing Chinese data.
Copyright (c) http://jspbbs.yeah.net
Package Lyf;
/**
* A class class.
* $#@60; p$#@62;
* @author Liuyufeng
*/