JSP Database Configuration: Create MySQL tables and Eclipse Projects

Source: Internet
Author: User

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:

 
 
  1. CREATE DATABASE'Test _ 2_3 '/*! 40100DEFAULT CHARACTER SETUtf8 */;DROP DATABASEIf exists 'test _ 2_3 ';
  2. USE 'test _ 2_3 ';
  3. CREATE TABLE'Users '(
  4. 'Id'Int(11)NOT NULLAuto_increment,
  5. 'Username'Varchar(16)Default NULL,
  6. `Password'Varchar(16)Default NULL,
  7. PRIMARY KEY('Id ')
  8. ) ENGINE = InnoDB AUTO_INCREMENT = 4DEFAULTCHARSET = utf8;
  9. Lock tables 'users' WRITE;
  10. /*! 40000ALTER TABLE'Users' disable keys */;
  11. INSERT INTO'Users'VALUES(1,'Test','123');
  12. INSERT INTO'Users'VALUES(2,'Huangt','123');
  13. INSERT INTO'Users'VALUES(3,'Cold moon silent','123');
  14. /*! 40000ALTER TABLE'Users' enable keys */;
  15. 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:

 
 
  1. # The well number is a comment symbol 
  2. # The following key-value pairs are configured for the MySQL database 
  3. # Configurations of other databases are similar. 
  4. # Put this file in the/WEB-INF/classes directory 
  5. # This method can effectively improve the portability and flexibility of web Applications 
  6.  
  7.  
  8. ConnJDBC. dbDriver = com. mysql. jdbc. Driver
  9. ConnJDBC. dbURL = jdbc: mysql:// Localhost: 3306/test_2_3? UseUnicode = true & characterEncoding = UTF-8 
  10. ConnJDBC. dbUsername = root
  11. 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)

  1. View the necessity of J2EE server and connection pool from the connection of JSP Database
  2. How to connect to MySQL database in JSP
  3. Connect to a database using JDBC
  4. Get database connection in JSP
  5. Necessity of JSP database connection pool

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.