Database--mysql-->java Articles

Source: Internet
Author: User
Tags stmt

Mysql

MySQL is a relational database management system developed by the Swedish MySQL AB company and is currently part of Oracle's product portfolio. MySQL is one of the most popular relational database management systems, and MySQL is the best RDBMS (relational database Management system) application software for WEB applications.
MySQL is a relational database management system, where relational databases store data in different tables rather than putting all of the data in a large warehouse, which increases speed and increases flexibility.
The SQL language used by MySQL is the most commonly used standardized language for accessing databases. MySQL software has adopted a dual licensing policy, divided into community and commercial version, due to its small size, fast, low total cost of ownership, especially the open source, the development of the general small and medium-sized web site to choose MySQL as the site database.

Show Command 1. Displays the list of databases. Show Databases;2. Display the data table in the library: use MySQL;//Open Library 3. Display the structure of the data table: describe table name; 4. Build Library: Create database name; 5. Build table: Use library name, create table table name (field settings list);
(column_name column_type); 
6. Delete Library and delete table: drop database name; drop table name; 7. Empty the records in the table: Delete from table name; 8. Show Records in table: SELECT * from table name;

MySQL installation is used

Personal comparison recommended 5.7 version of the database, this is more suitable for a variety of computer problems, can not install MySQL, more to the online search installation tutorial

Working with MySQL database in Java
    1. First, install the database.
    2. Import the MySQL jar package-->mysql-connector-java-5.1.13-bin.jar
      • First create a folder, the jar package into which, generally named Lib;
      • Right-click the jar package that appears click Build path--> click Add to build path, so the jar package import is completed
Code Demo:
 Public classMysql {StaticString dbdoriver= "Com.mysql.jdbc.Driver"; //is the local MySQL database: localhost:3306, installation is generally 3306, the changed is not, Myta is the database name, the others are almost the same    StaticString dburl= "Jdbc:mysql://localhost:3306/myta?useunicode=true&characterencoding=utf-8"; StaticString dbname= "root";//Log In User name    StaticString dbpwd= "123456";//Log in Password    StaticConnection conn=NULL;  Public  voidgetconnection () {Try{class.forname (dbdoriver);//load driver, connect MySQL jdbcConn=drivermanager.getconnection (DBURL,DBNAME,DBPWD);//connecting to a databaseSystem.out.println ("Link succeeded"); Statement stmt=conn.createstatement ();//Create an Statement object, which is an interface to the databaseString sql= "Select*from mytable"; ResultSet RSet=stmt.executequery (SQL);//put the results of the search into the result set            while(Rset.next ()) {//Traverse this result setSystem.out.println (rset.getstring (1) + "\ T" +rset.getstring (2));//output each data at once        }             }Catch(Exception e) {//Todo:handle ExceptionSystem.out.println (E.getmessage ()); }    }     Public Static voidMain (string[] args)throwsSQLException {mysql MySQL=NewMysql ();//Creating ObjectsMysql.getconnection ();//calling the Getconnection method    }}

Database--mysql-->java 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.