您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 绩效管理 > JAVAEE实验报告7-石博洋
《JavaEE与中间件技术专题实验》课程实验报告七班级:计算机1602班学号:201610333姓名:石博洋实验内容:(1)使用hibernate配置文件创建学生信息表(学号、姓名、性别、出生日期、班级)、班级信息表(班级编号、班级名称、开班日期)。(2)完成对班级和学生信息的增删改查。(3)使用hibernate完成两表的主外键关联。(选做)(4)将配置文件配置成单向多对一,完成对班级和学生信息的增删改查。(选做)一、给出实现方案。首先配置好hibernate,实现和数据库的连接,在java类中创建对数据库的各种操作,实现对数据库的增删查改,在数据库中建立数据库login实现和程序的连接,创建两个表,并建立两个表的主外键。然后在程序中实现各种映射。二、给出项目结构和核心代码。Student.java:packagecom.edu.entity;publicclassStudent{privateIntegerid;privateStringstudentid;privateStringname;privateStringsex;privateStringbirthday;privateStringclassname;publicIntegergetId(){returnid;}publicvoidsetId(Integerid){this.id=id;}publicStringgetStudentid(){returnstudentid;}publicvoidsetStudentid(Stringstudentid){this.studentid=studentid;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetSex(){returnsex;}publicvoidsetSex(Stringsex){this.sex=sex;}publicStringgetBirthday(){returnbirthday;}publicvoidsetBirthday(Stringbirthday){this.birthday=birthday;}publicStringgetClassname(){returnclassname;}publicvoidsetClassname(Stringclassname){this.classname=classname;}publicStudent(){super();}publicStudent(Stringstudentid,Stringname,Stringsex,Stringbirthday,Stringclassname){super();this.studentid=studentid;this.name=name;this.sex=sex;this.birthday=birthday;this.classname=classname;}}ClassInfo.java:packagecom.edu.entity;publicclassClassInfo{privateIntegerid;privateStringclassid;privateStringclassname;privateStringdate;publicIntegergetId(){returnid;}publicvoidsetId(Integerid){this.id=id;}publicStringgetClassid(){returnclassid;}publicvoidsetClassid(Stringclassid){this.classid=classid;}publicStringgetClassname(){returnclassname;}publicvoidsetClassname(Stringclassname){this.classname=classname;}publicStringgetDate(){returndate;}publicvoidsetDate(Stringdate){this.date=date;}publicClassInfo(Stringclassid,Stringclassname,Stringdate){this.classid=classid;this.classname=classname;this.date=date;}publicClassInfo(){super();}}Student.hbm.xml:?xmlversion=1.0?!DOCTYPEhibernate-mappingPUBLIC-//Hibernate/HibernateMappingDTD3.0//EN=com.edu.entity.Studenttable=STUDENTidname=idtype=java.lang.Integercolumnname=ID/generatorclass=native//idpropertyname=studentidtype=java.lang.Stringcolumnname=STUDENTID//propertypropertyname=nametype=java.lang.Stringcolumnname=NAME//propertypropertyname=sextype=java.lang.Stringcolumnname=SEX//propertypropertyname=birthdaytype=java.lang.Stringcolumnname=BIRTHDAY//propertypropertyname=classnametype=java.lang.Stringcolumnname=CLASSNAME//property/class/hibernate-mappingClassInfo.hbm.xml:?xmlversion=1.0?!DOCTYPEhibernate-mappingPUBLIC-//Hibernate/HibernateMappingDTD3.0//EN=com.edu.entity.ClassInfotable=CLASSidname=idtype=java.lang.Integercolumnname=ID/generatorclass=native//idpropertyname=classidtype=java.lang.Stringcolumnname=CLASSID//propertypropertyname=classnametype=java.lang.Stringcolumnname=CLASSNAME//propertypropertyname=datetype=java.lang.Stringcolumnname=DATE//property/class/hibernate-mappingHibernate.cfg.xml:?xmlversion=1.0encoding=UTF-8?!DOCTYPEhibernate-configurationPUBLIC-//Hibernate/HibernateConfigurationDTD3.0//EN=connection.driver_classcom.mysql.jdbc.Driver/propertypropertyname=connection.urljdbc:mysql:///class_student/propertypropertyname=connection.usernameroot/propertypropertyname=connection.password123456/propertypropertyname=dialectorg.hibernate.dialect.MySQL5InnoDBDialect/propertypropertyname=hbm2ddl.autoupdate/propertypropertyname=show_sqltrue/propertypropertyname=format_sqltrue/propertymappingresource=com/edu/entity/Student.hbm.xml/mappingresource=com/edu/entity/ClassInfo.hbm.xml//session-factory/hibernate-configurationpackagecom.edu.entity;importjava.util.Scanner;importorg.hibernate.Session;importorg.hibernate.SessionFactory;importorg.hibernate.Transaction;importorg.hibernate.boot.registry.StandardServiceRegistryBuilder;importorg.hibernate.cfg.Configuration;importorg.hibernate.service.ServiceRegistry;publicclassStudentInsertMain{publicstaticvoidmain(String[]args){Scannercin=newScanner(System.in);SessionFactorysessionFactory=null;Sessionsession=null;Transactiontransaction=null;Configurationconfiguration=newConfiguration().configure();ServiceRegistryserviceRegistry=newStandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();sessionFactory=configuration.buildSessionFactory(serviceRegistry);session=sessionFactory.openSession();System.out.println(请依次输入学号姓名性别出生日期班级:);Stringstudentid=cin.next();Stringname=cin.next();Stringsex=cin.next();Stringbirthday=cin.next();Stringclassname=cin.next();Studentstudent=newStudent(studentid,name,sex,birthday,classname);transaction=s
本文标题:JAVAEE实验报告7-石博洋
链接地址:https://www.777doc.com/doc-6015514 .html