本周首先暫時結束了java進階知識,進入到了資料庫的學習:
java進階部分:
1.多線程:線程並發(多個線程操作共用變數);
鎖機制,關鍵字有synchronize(並發安全執行緒,可鎖對象和方法),wait,notify
(悲觀)死結,,wait,notify,notifyAll;
2.網路編程:UDP資料廣播(資料寄件者只需向交換器發送一個拷貝,交換器負責將這個資訊製作n個拷貝發送給所有機器)
Http協議(HyperText Transfer Protocol)
Json資料格式,文法規則:JSON對象{"屬性名稱":"屬性值"}
JSON數組["元素1","元素2"...]
JSON外掛程式:- Json-lib
- Gson
- Jackson
- FastJSON - alibaba
;
資料庫部分:(採用mysql5.5資料庫,以及navicat圖形工具對其操作)
3.系統以及mysql常用命令
系統命令(以管理員身份運行)
: #啟動服務
net start mysql
#停止服務
net stop mysql
#進入mysql命令列
mysql -uroot -p密碼
#退出mysql命令列
exit
#修改密碼
mysqladmin -uroot -p123456 password 密碼
#備份資料庫執行個體 mysqldump -uroot -proot mydb > d:/mydb.sql
#備份表 mysqldump -uroot -proot mydb tbuser > d:/tbuser.sql
Mysql常用命令
: --顯示資料庫執行個體
show databases;
--建立資料庫執行個體
create database mydb;
--使用資料庫執行個體
user mydb;
--顯示執行個體中所有資料庫表
show tables;
SQL語句
auto_increment:設定列自增,可用於主鍵列以及非空唯一列(not null unique)
unsigned:設定無符號列(列值不允許為負數)
zerofill:設定零填充列(當列資料長度不到定義長度時,數值前補0)
4.SQL語句:
DDL(資料庫定義語言:用來建立資料庫、資料庫物件和定義其列):create、desc(查看錶結構)、alter、drop
DML (資料庫操縱語言:增刪改查):select、insert、delete、update;
DCL(資料庫控制語言:控制許可權)revork,grant;
5.(完整性條件)約束:1. 主鍵約束
2. 外鍵約束
3. 不為空白約束
4. 唯一約束
5. 檢查約束(mysql暫不支援)
6.資料類型、運算子
7.查詢(重點):SELECT 查詢列1,查詢列2,...
FROM 目標表
【WHERE 查詢條件】
【GROUP BY 列名稱】
【HAVING 查詢條件】
【ORDER BY 列名稱 ASC|DESC】
【LIMIT [位移行,]記錄行數】
單表查詢:模糊查詢(“%”,“_”),彙總函式
多表查詢:等值串連,外串連
mysql函數的使用。
import java.io.Serializable;/** * 工作詳情類 * @author NIUXUYUAN */public class Jobs implements Serializable{/** * */private static final long serialVersionUID = 1L;private String id; //idprivate 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;}@Overridepublic 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資料庫及簡單作業碼
資料庫基礎知識