search
HomeDatabaseMysql TutorialOperation code for database part knowledge using JAVA

This week, we first temporarily ended the advanced knowledge of java and entered the study of database:

Advanced part of java:
          1. Multi-threading: Thread concurrency (multiple threads operate shared variables) ;
lock mechanism, keywords are synchronize (safety, lock objects and methods), WAIT, notify
(pessimistic) dead lock, wait, notify, notifyall;
2. Network programming: UDP data broadcast (the data sender only needs to send one copy to the switch, and the switch is responsible for making n copies of this information and sending it to all machines)
                                     Http Protocol (HyperText Transfer Protocol)
                           Json data format, syntax rules: JSON Object {"attribute name": "Attribute value"}
json array ["Element 1", "Element 2" ...]
JSON plug-in: -JSON-LIB
- Gson ##- Jackson
- Fastjson -Alibaba
;
database part: (using MySQL5.5 database, and Navicat graphics tools to operate)
3. System and MySQL commonly used command
system commands (with by the Run as administrator)

: #Start service

net start mysql

                                                                                                                                                                                                  ’s ’s ’s ’ s ’ s ’ ‐     ‐   ‐   ‐ ‐‐ ‐‐ net stop mysql


                                                               
mysql -uroot -p password

                                                                                                                                                                  

#                                                                                                                                                                                                                                                             Backup database instance mysqldump -uroot -proot mydb > d:/mydb.sql
                                                                                                                                                                        ’ s ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ d:/mydb.sql to uroot -proot mydb tbuser > d:/tbuser.sql  
                 

Mysql common commands

:-Show the database instance
Show databases;

-Create the database instance
Create database Mydb;

-Display all database tables in the instance
Show Tables;
## SQL statement

# Auto_increment: Set up columns, which can be used for the primary key column and the unique column of non -air (not null unique)

                                                                                                                                                                                                                                                                                       ​​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​When defining the length, add 0 to the front of the value)

, alter, drop

                                                                                                         . Language: control authority) revork, grant;

                5. (Integrity Conditions) Constraints: 1. Primary key constraint
2. Foreign key constraint

3. Not empty constraint

4. Unique constraint
5. Check constraint (mysql does not support it yet)

                                                                                                                                                                                                                                          .         FROM target table


                                                                                                                                                                                                                                     ​ 


【GROUP BY column Name】

## [HAVING Query Conditions]

## 【Order By column name ASC | Desc】




                                                【LIMIT [偏移行,]记录行数】
  
                                              单表查询:模糊查询(“%”,“_”),聚合函数
                                              多表查询:等值连接,外连接
                                              mysql函数的使用。

import java.io.Serializable;

/**
 * 工作详情类
 * @author NIUXUYUAN
 */
public class Jobs implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String id;          //id
	private String experience;  //工作经验
	private String city;        //工作地点
	private String industry;    //行业
	private String detail;      //工作详情
	private String company;     //公司
	private String jobname;     //职位
	public Jobs(String id, String experience, String city, String industry, String detail, String company,
			String jobname) {
		super();
		this.id = id;
		this.experience = experience;
		this.city = city;
		this.industry = industry;
		this.detail = detail;
		this.company = company;
		this.jobname = jobname;
	}
	
	@Override
	public String toString() {
		return "Jobs [id=" + id + ", experience=" + experience + ", city=" + city + ", industry=" + industry
				+ ", detail=" + detail + ", company=" + company + ", jobname=" + jobname + "]";
	}
	
	public String toString(int i) {
		return experience+city+industry+detail+company+jobname;
	}

	public Jobs() {
		// TODO Auto-generated constructor stub
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getExperience() {
		return experience;
	}

	public void setExperience(String experience) {
		this.experience = experience;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getIndustry() {
		return industry;
	}

	public void setIndustry(String industry) {
		this.industry = industry;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getJobname() {
		return jobname;
	}

	public void setJobname(String jobname) {
		this.jobname = jobname;
	}
	
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class AddJobs {

	static List<Jobs> list = new ArrayList<>();
	File file = new File("jobs");
	
	/**
	 * 输入数据
	 * @throws IOException
	 */
	public void input() throws IOException {
	     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	     System.out.println("以id/experience/education/city/industry/detail/company/jobname格式填入:");
	     String msg = "";
	     while(!(msg = br.readLine()).equalsIgnoreCase("quit")) {
	    	 add(msg);
	     }
	     br.close();
	}

	/**
	 * 将数据变为Jobs对象存入list集合
	 * @param msg
	 */
	private void add(String msg) {
		String[] s = msg.split("/");
		Jobs job = new Jobs(s[0], s[1], s[2], s[3], s[4], s[5], s[6]);
		list.add(job);
	}
	
	private void checkFile() throws FileNotFoundException, IOException, ClassNotFoundException {
		if(file.length()>0) {
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
		List<Jobs> temp = (List<Jobs>)ois.readObject();
		if(temp!=null) {
			list.clear();
			for(Jobs t:temp) {
				list.add(t);
			}
		}
		ois.close();
		}
	}
	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		AddJobs aj = new AddJobs();
		if(!aj.file.exists()) {
			aj.file.createNewFile();
		}
		aj.checkFile();
		aj.input();
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(aj.file));
		oos.writeObject(list);
		oos.close();
	}

}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

public class Query {

	static List<Jobs> list = new ArrayList<>();
	File file = new File("jobs");

	/**
	 * 查看file文件,将数据导入list集合
	 * @throws FileNotFoundException
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	private void checkFile() throws FileNotFoundException, IOException, ClassNotFoundException {
		if(file.length()>0) {
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
		List<Jobs> temp = (List<Jobs>)ois.readObject();
		if(temp!=null) {
			list.clear();
			for(Jobs t:temp) {
				list.add(t);
			}
		}
		ois.close();
		}
	}
	
	public void check() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("请输入experience/education/city/industry/detail/company/jobname的某些信息");
		String msg = br.readLine();
		String[] s = msg.split("/");
		String regex = "";
		for (String str : s) {
			regex += "[\\s\\S]*" + str + "[\\s\\S]*";
		}
		List<Jobs> temp = new ArrayList<>();
		for (Jobs j : list) {
			msg = j.toString(1);
			if(msg.matches(regex)) {
				temp.add(j);
			}
		}
		System.out.println("结果");
		for (Jobs jobs : temp) {
			System.out.println(jobs);
		}
	}
	public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException, IOException {
		Query q = new Query();
		q.checkFile();
		q.check();
	}
}

 相关文章:

Java连接MySQL数据库及简单操作代码

数据库基础知识

The above is the detailed content of Operation code for database part knowledge using JAVA. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool