In this example, there are many things that are the same as in the previous "JSP + JavaBean User Logon example supports Chinese user names)", including the demonstration effect, only the properties file is used, and some modifications are made in the corresponding program. This example also supports Chinese characters.
Step 1 of JSP Database Configuration
Create the database test_2_3 in MySQL and create the table users. The structure is as follows:
The SQL script is:
- CREATE DATABASE'Test _ 2_3 '/*! 40100DEFAULT CHARACTER SETUtf8 */;DROP DATABASEIf exists 'test _ 2_3 ';
- USE 'test _ 2_3 ';
- CREATE TABLE'Users '(
- 'Id'Int(11)NOT NULLAuto_increment,
- 'Username'Varchar(16)Default NULL,
- `Password'Varchar(16)Default NULL,
- PRIMARY KEY('Id ')
- ) ENGINE = InnoDB AUTO_INCREMENT = 4DEFAULTCHARSET = utf8;
- Lock tables 'users' WRITE;
- /*! 40000ALTER TABLE'Users' disable keys */;
- INSERT INTO'Users'VALUES(1,'Test','123');
- INSERT INTO'Users'VALUES(2,'Huangt','123');
- INSERT INTO'Users'VALUES(3,'Cold moon silent','123');
- /*! 40000ALTER TABLE'Users' enable keys */;
- Unlock tables;
Step 2 of JSP Database Configuration
Create Project test_2_4 in eclipse, create a new database dynamic configuration file init. properties under src, this file is output to the file output to the/WEB-INF/classes directory. Code:
- # The well number is a comment symbol
- # The following key-value pairs are configured for the MySQL database
- # Configurations of other databases are similar.
- # Put this file in the/WEB-INF/classes directory
- # This method can effectively improve the portability and flexibility of web Applications
-
-
- ConnJDBC. dbDriver = com. mysql. jdbc. Driver
- ConnJDBC. dbURL = jdbc: mysql:// Localhost: 3306/test_2_3? UseUnicode = true & characterEncoding = UTF-8
- ConnJDBC. dbUsername = root
- ConnJDBC. dbPassword = 123456
(In the eclipse project src file set up to the/WEB-INF/classes directory, that is, int. properties should be stored in the location)
- View the necessity of J2EE server and connection pool from the connection of JSP Database
- How to connect to MySQL database in JSP
- Connect to a database using JDBC
- Get database connection in JSP
- Necessity of JSP database connection pool