MySQL simple use-mysql tutorial

Source: Internet
Author: User
Tags mysql tutorial
MySQL simple use 1. http protocol (understanding) (1) What is http protocol (HyperText Transfer Control Protocol )? An application layer protocol defined by w3c is used to define the communication process and data format between the browser and the web server. 1), the process of communication between the browser and the server: Step 1. establish the connection with the server. Step 2: package the browser

MySQL simple use 1. http protocol (understanding) (1) What is http protocol (HyperText Transfer Control Protocol )? An application layer protocol defined by w3c is used to define the communication process and data format between the browser and the web server. 1), the process of communication between the browser and the server: Step 1. establish the connection with the server. Step 2: package the browser

Simple use of MySQL
1. http protocol (learn more)
(1) What is http (HyperText Transfer Control Protocol )?
An application layer protocol defined by w3c, used to define the relationship between a browser and a web
The communication process between servers and the data format.
1) communication between the browser and the server:
Step 1: establish a connection with the server
Step 2: package the browser (according to http protocol requirements) and send the request
Step 3: package the server and send a response
Step 4: close the connection on the server
Features: one request and one connection.
Advantage: The server can use limited connections as many clients as possible
Service.
2) Data Format
A. request data packets
Request Line: type and version of the resource path protocol requested by the request method
Several message headers:
The message header is a key-value pair, which is usually used by browsers or servers.
Automatically generated, indicating the specific meaning. For example, a browser can
Send the user-agent message header to inform the server of the browser type and version.
Entity content:
The browser will add request parameters
Here, for a get request, the request parameters are added to the Request resource.
Path.
B. response packet
Status line: Protocol Type and version status code status description
The status code is a three-digit number defined by w3c, indicating the server
A request processing status, such:
404: the corresponding resource cannot be found based on the Request resource path.
500: a system error occurred.
200: Normal
Several message headers:
For example, the server can send a content-type
Indicates the type of data returned by the browser.
Entity content:
Result of program processing
2. get and post requests
(1) in which cases, the browser sends a get request
A. enter an address in the browser address bar.
B. click the link.
C. The form is submitted by default.
(2) in which case, the browser sends a post request
A. method = "post" is set for the form ".
(3) get request features
A. The request parameters are added to the end of the Request resource path and can only be submitted.
A small amount of data is sent to the server.
B. The request parameters are displayed in the browser address bar, which is insecure (for example
Will record this address ).
(4) post request features
A. The request parameters are added to the object content to provide a large amount of data.
To the server.
B. The request parameters are not displayed in the browser address bar, which is relatively secure (post mode ).
Does not encrypt request parameters ).

3. coding problems in web coding
1) common sense:
A. The java language saves all characters in the memory in unicode encoding format.
B. encoding: convert the byte array corresponding to the unicode encoding format into
C. The byte array corresponding to the local encoding format (gbk, gb2312, UTF-8.
Decoding: converts a byte array corresponding to a local encoding format to unicode.
The byte array corresponding to the encoding format.
2) If a servlet on the server needs to output Chinese characters to the client
Add the following code:
Response. setContentType ("text/html; charset = utf-8 ");
This line of code has two functions:
1st: out. println, use the correct encoding format for encoding
(Unicode --> UTF-8)
2nd: content-type message header set, browser
The page will be opened (Decoded) according to the specified encoding format)

4. form processing
(1) how to obtain the request parameter value in the form?
A, String request. getParameter (String paraName );
Note:
A1, paraName is incorrect, and null is obtained.
A2. in the text input box, if not entered, an empty string is obtained.
B, String [] request. getParameterValues (String paraName );
If multiple parameters have the same name, use this method.
(2) What should I do if the form contains a Chinese parameter value?
When the form is submitted, the browser will encode the parameter values in the form.
(The encoding format is used to encode the page where the form is opened ). Server
By default, decoding with a ISO-8859-1 is possible
Garbled problem.
Solution 1:
Step 1: ensure that the page where the form is located is opened in the specified encoding format.
For example, for html files, you can add:

Content = "text/html; charset = utf-8"/>
Also, set method = "post ".
Step 2: on the server side
// Tell the server to use the specified encoding format for decoding
// Valid only for post requests.
Request. setCharacterEncoding ("UTF-8 ");
Solution 2:
Step 1, same as above. The method attribute is not required.
Step 2,
Name = new String (name. getBytes ("iso-8859-1 "),
"UTF-8 ");

Go ftp download mysql-connector-java-5.1.7-bin.jar
This is the jdbc driver of mysql.
5. simple use of mysql databases
1) log on to the database (use the root user to log on)
Mysql-uroot;
2) View database instances
Show databases;
3) Create a new database
Create a database named jd130db. the default value of this database is
UTF-8 character set
Create database jd130db default character set utf8;
4) use a database
Use jd130db;
5) view the tables in the current database
Show tables;
6) create a table
Create table t_emp (
Id int primary key auto_increment,
Name varchar (50 ),
Salary double,
Age int
);
Primary key: Master key constraint
Auto_increment: Auto-increment column. when a record is inserted
Automatic assignment.
Insert into t_emp (name, salary, age) values ('Tom ', 20000,20 );

6. how does servlet access the database?
Step 1, copy the database driver to the WEB-INF \ lib.
Step 2: write jdbc code to access the database, and pay attention to exception handling.


Create a database named dolojia with UTF-8 encoding
Create database dolojia default character set utf8;
Set the database password to Aa123465 and grant the permission to add, delete, modify, and query data.
Grant select, insert, update, delete, create, drop on dolojia. * to localhost Identified by "Aa123456 ";
Refresh
Flush privileges;

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.