当前位置: 首页 > news >正文

东莞市专注网站建设怎么样单位网站建设情况说明

东莞市专注网站建设怎么样,单位网站建设情况说明,品牌注册怎么注册,做网站建设网站制作Hibernate是什么#xff1a; Hibernate 架构#xff1a; 下载、安装、必要的 jar包、环境CLASSPAST的设置#xff08;此步骤省略#xff09; Hibernate框架的使用步骤#xff1a;1、创建Hibernate的配置文件#xff08;hibernate.cfg.xml#xff09;2、创建持久化类 Hibernate 架构 下载、安装、必要的 jar包、环境CLASSPAST的设置此步骤省略 Hibernate框架的使用步骤 1、创建Hibernate的配置文件hibernate.cfg.xml2、创建持久化类即事实上例须要保存到数据库中的类User.java3、创建对象-关系映射文件User.hbm.xml 4、通过Hibernate API编写訪问数据库的代码 配置文件 hibernate.cfg.xml ?xml version1.0 encodingutf-8? !DOCTYPE hibernate-configuration SYSTEM http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtdhibernate-configurationsession-factoryproperty namehibernate.dialectorg.hibernate.dialect.MySQLDialect/propertyproperty namehibernate.connection.driver_classcom.mysql.jdbc.Driver/property!-- Assume testone is the database name --property namehibernate.connection.urljdbc:mysql://localhost/testone/propertyproperty namehibernate.connection.usernameroot/propertyproperty namehibernate.connection.passwordyanfei/propertyproperty namehibernate.show_sqltrue/property!-- List of XML mapping files --mapping resourceresource/Employee.hbm.xml //session-factory /hibernate-configuration 创建持久化类 package com.jiangge.hblearn;/*** author jiangge* */ public class Employee {private int id;private String firstName;private String lastName;private int salary;public Employee(){}public Employee(String firstName, String lastName, int salary){super();this.firstName firstName;this.lastName lastName;this.salary salary;}public int getId(){return id;}public void setId(int id){this.id id;}public String getFirstName(){return firstName;}public void setFirstName(String firstName){this.firstName firstName;}public String getLastName(){return lastName;}public void setLastName(String lastName){this.lastName lastName;}public int getSalary(){return salary;}public void setSalary(int salary){this.salary salary;} }创建数据库中的表 create table EMPLOYEE (id INT NOT NULL auto_increment,first_name VARCHAR(20) default NULL,last_name VARCHAR(20) default NULL,salary INT default NULL,PRIMARY KEY (id) ); 配置文件--映射文件Employee.hbm.xml ?xml version1.0 encodingutf-8? !DOCTYPE hibernate-mapping PUBLIC -//Hibernate/Hibernate Mapping DTD//ENhttp://www.hibernate.org/dtd/hibernate-mapping-3.0.dtdhibernate-mappingclass namecom.jiangge.hblearn.Employee tableEMPLOYEEmeta attributeclass-descriptionThis class contains the employee detail./metaid nameid columnid typeintgenerator classnative //idproperty namefirstName columnfirst_name typestring /property namelastName columnlast_name typestring /property namesalary columnsalary typeint //class /hibernate-mapping创建測试文件--CURD操作 package com.jiangge.hblearn;import java.util.List; import java.util.Iterator;import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration;/*** hibernate CRUD操作* author jiangge*/ public class ManageEmployee {private static SessionFactory factory;public static void main(String[] args){try{factory new Configuration().configure().buildSessionFactory();} catch (Throwable ex){System.err.println(Failed to create sessionFactory object. ex);throw new ExceptionInInitializerError(ex);}ManageEmployee ME new ManageEmployee();/* Add few employee records in database */Integer empID1 ME.addEmployee(Zara, Ali, 1000);Integer empID2 ME.addEmployee(Daisy, Das, 5000);Integer empID3 ME.addEmployee(John, Paul, 10000);/* List down all the employees */ME.listEmployees();/* Update employees records */ME.updateEmployee(empID1, 5000);/* Delete an employee from the database */ME.deleteEmployee(empID2);/* List down new list of the employees */ME.listEmployees();}/* Method to CREATE an employee in the database */public Integer addEmployee(String fname, String lname, int salary){Session session factory.openSession();Transaction tx null;Integer employeeID null;try{tx session.beginTransaction();Employee employee new Employee(fname, lname, salary);employeeID (Integer) session.save(employee);tx.commit();} catch (HibernateException e){if (tx ! null)tx.rollback();e.printStackTrace();} finally{session.close();}return employeeID;}/* Method to READ all the employees */public void listEmployees(){Session session factory.openSession();Transaction tx null;try{tx session.beginTransaction();List employees session.createQuery(FROM Employee).list();for (Iterator iterator employees.iterator(); iterator.hasNext();){Employee employee (Employee) iterator.next();System.out.print(First Name: employee.getFirstName());System.out.print( Last Name: employee.getLastName());System.out.println( Salary: employee.getSalary());}tx.commit();} catch (HibernateException e){if (tx ! null)tx.rollback();e.printStackTrace();} finally{session.close();}}/* Method to UPDATE salary for an employee */public void updateEmployee(Integer EmployeeID, int salary){Session session factory.openSession();Transaction tx null;try{tx session.beginTransaction();Employee employee (Employee) session.get(Employee.class, EmployeeID);employee.setSalary(salary);session.update(employee);tx.commit();}catch (HibernateException e){if (tx ! null)tx.rollback();e.printStackTrace();} finally{session.close();}}/* Method to DELETE an employee from the records */public void deleteEmployee(Integer EmployeeID){Session session factory.openSession();Transaction tx null;try{tx session.beginTransaction();Employee employee (Employee) session.get(Employee.class, EmployeeID);session.delete(employee);tx.commit();}catch (HibernateException e){if (tx ! null)tx.rollback();e.printStackTrace();} finally{session.close();}} } 执行结果IDE的Console输出 log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. Hibernate: insert into EMPLOYEE (first_name, last_name, salary) values (?, ?, ?) Hibernate: insert into EMPLOYEE (first_name, last_name, salary) values (?, ?, ?) Hibernate: insert into EMPLOYEE (first_name, last_name, salary) values (?, ?, ?) Hibernate: select employee0_.id as id0_, employee0_.first_name as first2_0_, employee0_.last_name as last3_0_, employee0_.salary as salary0_ from EMPLOYEE employee0_ First Name: Zara Last Name: Ali Salary: 1000 First Name: Daisy Last Name: Das Salary: 5000 First Name: John Last Name: Paul Salary: 10000 Hibernate: select employee0_.id as id0_0_, employee0_.first_name as first2_0_0_, employee0_.last_name as last3_0_0_, employee0_.salary as salary0_0_ from EMPLOYEE employee0_ where employee0_.id? Hibernate: update EMPLOYEE set first_name?, last_name?, salary? where id? Hibernate: select employee0_.id as id0_0_, employee0_.first_name as first2_0_0_, employee0_.last_name as last3_0_0_, employee0_.salary as salary0_0_ from EMPLOYEE employee0_ where employee0_.id? Hibernate: delete from EMPLOYEE where id? Hibernate: select employee0_.id as id0_, employee0_.first_name as first2_0_, employee0_.last_name as last3_0_, employee0_.salary as salary0_ from EMPLOYEE employee0_ First Name: Zara Last Name: Ali Salary: 5000 First Name: John Last Name: Paul Salary: 10000 MySQL数据库数据 mysql select * from EMPLOYEE; ----------------------------------- | id | first_name | last_name | salary | ----------------------------------- | 1 | Zara | Ali | 5000 | | 3 | John | Paul | 10000 | ----------------------------------- 2 rows in set 參考文献 1、英文 http://www.tutorialspoint.com/hibernate/hibernate_quick_guide.htm   2、中文http://blog.csdn.net/zs234/article/details/9212045 入门系列文章 我是没用得分隔线 Hibernate框架的使用步骤 1、创建Hibernate的配置文件hibernate.cfg.xml2、创建持久化类即事实上例须要保存到数据库中的类User.java3、创建对象-关系映射文件User.hbm.xml 4、通过Hibernate API编写訪问数据库的代码 Hibernate配置文件         Hibernate配置文件从形式来讲有两种基本的格式: 一种是Java属性文件即*.properties这样的配置格式主要定义连接数据库须要的參数另一种是XML格式的文件这样的文档除了能够定义连接数据库须要的參数还能够定义程序中用的映射文件。所以普通情况下使用XML格式的配置文档。 映射的概念     映射即对象关系映射(Object Relational Mapping)。ORM的实现目的就是将对象数据保存到数据库中同一时候能够将数据库数据读入对象中    这样开发者就能够将对数据库数据的操作转化为对这些对象的操作。 注解配置基本映射实例     除了XML方式User.hbm.xml配置映射外还能够通过给类文件加入注解的方式配置映射比如           Entiey           Table(nameuser)    很多其它内容请英文keyword搜索「hibernate annotations tutorial」 关系映射分类        关系映射即在基本映射的基础上处理多个相关对象和多个相关表之间联系的映射。关系映射从相应关系的角度能够分为例如以下七种类型 一对一单向关联 一对一双向关联 一对多单向关联 多对一单向关联 一对多双向关联 多对多单向关联 多对多双向关联 转载于:https://www.cnblogs.com/yxwkf/p/3839643.html
http://www.yutouwan.com/news/447445/

相关文章:

  • 旅行社网站怎么做seo优化软件oem
  • 广州模板网站建设价格长春行业网站
  • 网站模板漏洞北京装饰公司招聘信息
  • 在印尼用哪个网站做电商微信h5页面制作模板
  • 怎样做网站赚钱医疗ppt模板下载免费完整版
  • 网站怎么让百度收录一张图做封面网站建设合同示范文本
  • html5网站建设加盟如何备份网站数据
  • 百度快照网站怎么做加强网站的建设与管理
  • 北京企业网站改版开鲁网站seo转接
  • 网页制作与网站建设实战大全pdf【郑州网站建设】
  • 阿里网站备案寄材料百度怎么优化网站排名
  • 网站手机端制作软件免费的网站管理系统
  • 建设彩票网站如何盈利建网站需要哪些资质
  • 模具 东莞网站建设如何不花钱开发网站
  • 一级a做爰网站中铁建设集团招聘信息
  • 图片外链上传网站济宁祥云网站建设
  • 站长网站装饰公司简易手机网站
  • window部署wordpress网站换域名了怎么办seo
  • 网站转换模块怎么做成都好玩的地方
  • 院系网站建设网站数据库5g
  • 纯静态 网站网站建设归哪个部门
  • 寿光做网站的怎样可以提升自己的网站
  • 名人网站设计版式濮阳网站
  • 做关键词排名卖网站wordpress调用api接口
  • 学校网站维护怎么做长沙网站建设长沙
  • 自己的网站怎么做搜索引擎如何分析竞争对手的网站
  • 做公司网站的步骤销售网络平台建设
  • 地方房地产网站seo实战案例分享网页设计教程132
  • 肥西网站推广公司网站开发和移动开发
  • 上海锦都建设(集团)有限公司网站客户管理软件 crm