Java Connection MySQL Simple implementation

Source: Internet
Author: User
Tags mysql command line

Because recently to do a specific application involving the database, select database MySQL, java connection to MySQL to do a student information management system of a simple version.

Tool: Eclipse,jdbc,mysql

As in the previous article, MySQL is a free-to-install version and does not have a visualization, so use the command line to perform operations on the database.

1. Login

Enter the relevant directory after entering the command to login

Mysql-u root-p

You can view the existing database after logging in: show databases;

2. Create a new database

Create a new database studentbase and view it.

Create database studentbase;show databases;

You can see that the newly created database is already displayed in the list.

3. Create a table in a new database

It is not used immediately after the database is created, so you need to choose to use the database:

Use Studentbase;

The database needs to be created only once, but every time you start MySQL you have to select a database, and of course there is a simple way to select the database at login. Such as:

shell> mysql-h host-u User-********

After selecting the database and starting to create the table in the library, we can start by looking at what's in the library. Statement:

mysql>set (0.00 sec)

You can see nothing in the library, so you can create a new table to hold student information, such as school number, name, gender, address and five basic information about birthdays. Examples of creating tables in the official manual are:

Mysql> CREATE TABLE Pet (name varchar), owner varchar,    species varchar ( C8>20), Sex CHAR (1), Birth date, death date);

And our creation process is:

Note If you enter the wrong input, you can choose to undo the input: \c

After creation I want to see the view of the table created, enter the directive: describe students; But found the hint error said that the table is found, the check found that the original created table when the name of the wrong table, will indicate that the changes can be queried.

Modify table name: ALTER TABLE sutdents rename students;

Then view the view, you can see the following view of the Designed table:

Some basic SQL statements:

Database:
Go to MySQL command line: mysql-uroot-p
View all databases: show databases;
Creating database: Create databases niu charset UTF8;
Delete databases: drop database niu;
Select database: Use databases;
View all tables: show tables;
View the statement that created the database: show create databases DatabaseName;
View the statement that created the table: Show create TABLE tablename;
View table structure: desc tablenmae;

Table:
Constraints
#自增长 auto_increment
#非空 NOT NULL
#默认值 default ' xx '
#唯一 Unique
#指定字符集 CharSet
#主键 PRIMARY Key

Java Connection MySQL Simple implementation

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.