Step-by-step Jsp + JavaBean tutorial (4)

Source: Internet
Author: User
Database operation applications of assumerver Pages + JavaBeans
The preceding describes a simple counter example of a JavaBean application. Of course, in the actual procedure, more database-related operations are involved, in this section, we will focus on how the assumerver Pages and JavaBeans operate databases. Here we have selected a representative and practical example, that is, user registration management, because it is frequently used online, whether it is registration Email, prize investigation, purchase of items, or joining the community, it will involve the issue of user registration. On the other hand, it is representative and involves the increase of database records, record display and other common operations, so we use user registration to open the knife.
The program is developed using Oracle j2.163.1, the runtime environment is Wiin2000 + Tomcat3.1, and the database system uses Oracle8.16i.
First, create a database demodb. The fields are shown below.
Username VARCHAR2 (20) user name
Password VARCHAR2 (20) password
Email VARCHAR2 (30) Email address
Homepage VARCHAR2 (50) home page
Signs VARCHAR2 (200) signature
Regtime DATE registration time
Next we will create several JavaBeans and JavaServer Pages files.
Db. java files (encapsulate database connections and some underlying operations)
Adduser. java file (read and add user data)
Newuser. jsp file (new user page, used to enter user registration information)
Donewuser. jsp file (add user registration information)
Listuser. jsp file (list of all registered users)
For the convenience of reading the code, I have made detailed comments and explanations in many places. For Java syntax structure related to JavaBean, please refer to Java books.
Db. java file
Note: This JavaBean encapsulates database connections and some underlying operations. Derived classes can directly call these methods. In addition, a toChinese method is provided to process Chinese data.
// Copyright (c) 2000 http://jspbbs.yeah.net
Package lyf;
/**
* A Class class.
* <P>
* @ Author liuyufeng
*/
// Declare the class library file
Import oracle. jdbc. driver .*;
Import java.net .*;
Import java. SQL .*;
Import java. lang .*;
Import java. io .*;
Import java. util .*;
Public class db
{
// Initialize member variables
Connection conn = null; // database Connection
ResultSet rs = null; // record set
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.