MySQL怎么实现Scott数据映射
这篇“MySQL怎么实现Scott数据映射”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“MySQL怎么实现Scott数据映射”文章吧。
1、SQLDROPTABLEIFEXISTS`tb_dept`;CREATETABLE`tb_dept`(`deptno`tinyint(2)UNSIGNEDNOTNULLCOMMENT'部门编号',`dname`varchar(14)CHARACTERSETutf8COLLATEutf8_general_ciNULLDEFAULTNULLCOMMENT'部门名称',`loc`varchar(13)CHARACTERSETutf8COLLATEutf8_general_ciNULLDEFAULTNULLCOMMENT'部门地址',PRIMARYKEY(`deptno`)USINGBTREE)ENGINE=InnoDBCHARACTERSET=utf8COLLATE=utf8_general_ciROW_FORMAT=Dynamic;INSERTINTO`tb_dept`VALUES(10,'ACCOUNTING','NEWYORK');INSERTINTO`tb_dept`VALUES(20,'RESEARCH','DALLAS');INSERTINTO`tb_dept`VALUES(30,'SALES','CHICAGO');INSERTINTO`tb_dept`VALUES(40,'OPERATIONS','BOSTON');-------------------------------------------------------------------DROPTABLEIFEXISTS`tb_emp`;CREATETABLE`tb_emp`(`empno`int(4)UNSIGNEDNOTNULL,`ename`varchar(10)CHARACTERSETutf8COLLATEutf8_general_ciNULLDEFAULTNULL,`job`varchar(9)CHARACTERSETutf8COLLATEutf8_general_ciNULLDEFAULTNULL,`mgr`int(4)UNSIGNEDNULLDEFAULTNULL,`hiredate`dateNULLDEFAULTNULL,`sal`decimal(7,2)NULLDEFAULTNULL,`comm`decimal(7,2)NULLDEFAULTNULL,`deptno`tinyint(2)UNSIGNEDNULLDEFAULTNULL,PRIMARYKEY(`empno`)USINGBTREE,INDEX`deptno`(`deptno`)USINGBTREE,CONSTRAINT`tb_emp_ibfk_1`FOREIGNKEY(`deptno`)REFERENCES`tb_dept`(`deptno`)ONDELETERESTRICTONUPDATERESTRICT)ENGINE=InnoDBCHARACTERSET=utf8COLLATE=utf8_general_ciROW_FORMAT=Dynamic;INSERTINTO`tb_emp`VALUES(7369,'SMITH','CLERK',7902,'1980-12-17',800.00,NULL,20);INSERTINTO`tb_emp`VALUES(7499,'ALLEN','SALESMAN',7698,'1981-02-20',1600.00,300.00,30);INSERTINTO`tb_emp`VALUES(7521,'WARD','SALESMAN',7698,'1981-02-22',1250.00,500.00,30);INSERTINTO`tb_emp`VALUES(7566,'JONES','MANAGER',7839,'1981-04-02',2975.00,NULL,20);INSERTINTO`tb_emp`VALUES(7654,'MARTIN','SALESMAN',7698,'1981-09-28',1250.00,1400.00,30);INSERTINTO`tb_emp`VALUES(7698,'BLAKE','MANAGER',7839,'1981-05-01',2850.00,NULL,30);INSERTINTO`tb_emp`VALUES(7782,'CLARK','MANAGER',7839,'1981-06-09',2450.00,NULL,10);INSERTINTO`tb_emp`VALUES(7788,'SCOTT','ANALYST',7566,'1987-04-19',3000.00,NULL,20);INSERTINTO`tb_emp`VALUES(7839,'KING','PRESIDENT',NULL,'1981-11-17',5000.00,NULL,10);INSERTINTO`tb_emp`VALUES(7844,'TURNER','SALESMAN',7698,'1981-09-08',1500.00,0.00,30);INSERTINTO`tb_emp`VALUES(7876,'ADAMS','CLERK',7788,'1987-05-23',1100.00,NULL,20);INSERTINTO`tb_emp`VALUES(7900,'JAMES','CLERK',7698,'1981-12-03',950.00,NULL,30);INSERTINTO`tb_emp`VALUES(7902,'FORD','ANALYST',7566,'1981-12-03',3000.00,NULL,20);INSERTINTO`tb_emp`VALUES(7934,'MILLER','CLERK',7782,'1982-01-23',1300.00,NULL,10);2、实体类2.1、Dept.java
/***部门*@authorHC**/publicclassDept{/***部门编号*/privateIntegerdeptno;/***部门名称*/privateStringdname;/***部门地址*/privateStringloc;publicDept(){}publicDept(Integerdeptno,Stringdname,Stringloc){this.deptno=deptno;this.dname=dname;this.loc=loc;}publicIntegergetDeptno(){returndeptno;}publicvoidsetDeptno(Integerdeptno){this.deptno=deptno;}publicStringgetDname(){returndname;}publicvoidsetDname(Stringdname){this.dname=dname;}publicStringgetLoc(){returnloc;}publicvoidsetLoc(Stringloc){this.loc=loc;}@OverridepublicStringtoString(){return"Dept{"+"deptno="+deptno+",dname='"+dname+'\''+",loc='"+loc+'\''+'}';}}2.2、Emp.java
/***员工*@authorHC*/publicclassEmp{/***员工编号*/privateIntegerempno;/***员工姓名*/privateStringename;/***工作*/privateStringjob;/***上级领导编号*/privateIntegermgr;/***受雇日期*/privateLocalDatehiredate;/***薪资*/privateDoublesal;/***奖金*/privateDoublecomm;/***部门编号*/privateIntegerdeptno;publicEmp(){}publicEmp(Integerempno,Stringename,Stringjob,Integermgr,LocalDatehiredate,Doublesal,Doublecomm,Integerdeptno){this.empno=empno;this.ename=ename;this.job=job;this.mgr=mgr;this.hiredate=hiredate;this.sal=sal;this.comm=comm;this.deptno=deptno;}publicIntegergetEmpno(){returnempno;}publicvoidsetEmpno(Integerempno){this.empno=empno;}publicStringgetEname(){returnename;}publicvoidsetEname(Stringename){this.ename=ename;}publicStringgetJob(){returnjob;}publicvoidsetJob(Stringjob){this.job=job;}publicIntegergetMgr(){returnmgr;}publicvoidsetMgr(Integermgr){this.mgr=mgr;}publicLocalDategetHiredate(){returnhiredate;}publicvoidsetHiredate(LocalDatehiredate){this.hiredate=hiredate;}publicDoublegetSal(){returnsal;}publicvoidsetSal(Doublesal){this.sal=sal;}publicDoublegetComm(){returncomm;}publicvoidsetComm(Doublecomm){this.comm=comm;}publicIntegergetDeptno(){returndeptno;}publicvoidsetDeptno(Integerdeptno){this.deptno=deptno;}@OverridepublicStringtoString(){return"Emp{"+"empno="+empno+",ename='"+ename+'\''+",job='"+job+'\''+",mgr="+mgr+",hiredate="+hiredate+",sal="+sal+",comm="+comm+",deptno="+deptno+'}';}}3、数据库模拟代码
publicclassDB{privatestaticList<Emp>emps=newArrayList<>();privatestaticList<Dept>depts=newArrayList<>();static{depts.add(newDept(10,"ACCOUNTING","NEWYORK"));depts.add(newDept(20,"RESEARCH","DALLAS"));depts.add(newDept(30,"SALES","CHICAGO"));depts.add(newDept(40,"OPERATIONS","BOSTON"));emps.add(newEmp(7369,"SMITH","CLERK",7902,LocalDate.of(1980,12,17),800D,null,20));emps.add(newEmp(7499,"ALLEN","SALESMAN",7698,LocalDate.of(1981,2,20),1600D,300D,30));emps.add(newEmp(7521,"WARD","SALESMAN",7698,LocalDate.of(1981,2,22),1250D,500D,30));emps.add(newEmp(7566,"JONES","MANAGER",7893,LocalDate.of(1981,4,2),2975D,null,20));emps.add(newEmp(7654,"MARTIN","SALESMAN",7698,LocalDate.of(1981,9,28),1250D,1400D,30));emps.add(newEmp(7698,"BLAKE","MANAGER",7839,LocalDate.of(1981,5,1),2850D,null,30));emps.add(newEmp(7782,"CLARK","MANAGER",7839,LocalDate.of(1981,6,9),2450D,600D,10));emps.add(newEmp(7788,"SCOTT","ANALYST",7566,LocalDate.of(1987,4,19),3000D,null,20));emps.add(newEmp(7839,"KING","PRESIDENT",null,LocalDate.of(1981,11,17),5000D,null,10));emps.add(newEmp(7844,"TURNER","SALESMAN",7698,LocalDate.of(1981,9,8),1500D,null,30));emps.add(newEmp(7876,"ADAMS","CLERK",7788,LocalDate.of(1987,5,23),1100D,350D,20));emps.add(newEmp(7900,"JAMES","CLERK",7698,LocalDate.of(1981,12,3),950D,null,30));emps.add(newEmp(7902,"FORD","ANALYST",7566,LocalDate.of(1981,12,3),3000D,null,20));emps.add(newEmp(7934,"MILLER","CLERK",7782,LocalDate.of(1982,1,23),1300D,400D,10));}publicstaticList<Emp>getEmps(){returnemps;}publicstaticList<Dept>getDepts(){returndepts;}}
以上就是关于“MySQL怎么实现Scott数据映射”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。