Hibernate配置XML连接数据库
一、hibernate.cfg.xml
1、配置连接Oracle
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory> <property name="hbm2ddl.auto">create</property>
<property name="dialect"> org.hibernate.dialect.Oracle9Dialec </property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE </property>
<property name="connection.username">system</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="format_sql">true</property>
<property name="show_sql">true</property> <mapping resource="cn/wym/hibernate/Users.hbm.xml" /> </session-factory>
</hibernate-configuration>
2、配置连接MySQL
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory> <property name="hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql:///test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">MysqlConnection</property>
<property name="hbm2ddl.auto">update</property> <property name="show_sql">true</property>
<property name="format_sql">true</property> <mapping resource="cn/wym/hiberate/domain/User.hbm.xml" /> </session-factory>
</hibernate-configuration>
3、配置连接Microsoft SQL 2005
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration> <session-factory>
<property name="hbm2ddl.auto">create</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=testhjxc</property>
<property name="connection.username">wym</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="myeclipse.connection.profile">MS2005</property>
<property name="format_sql">true</property>
<property name="show_sql">true</property>
<mapping resource="cn/wym/hiberate/domain/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
二、cn/wym/hiberate/domain/User.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!--该文件要清楚地表述出 类 和 表 的对应关系-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.wym.hiberate.domain"> <class name="User" table="user">
<id name="id" column="id"> <!-- 映射主键 -->
<generator class="native"> </generator>
</id>
<property name="name"/>
<property name="birthday"/> </class>
</hibernate-mapping>
三、cn/wym/hiberate/domain/User.java
package cn.wym.hiberate.domain;
import java.util.Date;
public class User {
private String name;
private int id;
private Date birthday;
/**
* 必须要有的
*/
public User() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
Hibernate配置XML连接数据库的更多相关文章
- hibernate.cfg.xml常见配置
转载自:http://blog.csdn.net/qiaqia609/article/details/9456489 <!--标准的XML文件的起始行,version='1.0'表明XML的版本 ...
- hibernate.cfg.xml 配置(摘录)
配置文件中映射元素详解 对象关系的映射是用一个XML文档来说明的.映射文档可以使用工具来生成,如XDoclet,Middlegen和AndroMDA等.下面从一个映射的例子开始讲解映射元素,映射文件的 ...
- Hibernate 注解时 hibernate.hbm.xml的配置方法 以及与SSH整合里的配置方式
①纯Hibernate开发: 当你在Bean中写入注解后,需要告诉hibernate哪些类使用了注解. 方法是在hibernate.hbm.xml文件中配置 <!DOCTYPE hibernat ...
- hibernate.cfg.xml配置(Oracle+c3p0)
说明:数据库:Oracle10g:连接池:c3p0 结构: 一.配置hibernate.cfg.xml <?xml version="1.0" encoding=" ...
- hibernate 非xml实体类配置方法!
hibernate 非xml实体类配置方法! 这个是hibernate.cfg.xml配置文件 <?xml version='1.0' encoding='UTF-8'?> <!DO ...
- hibernate.cfg.xml文件的配置模板和不同数据库的配置參数
(1)hibernate.cfg.xml文件的配置模板 <?xml version="1.0" encoding="UTF-8"?> <!DO ...
- Hibernate框架 主配置文件(Hibernate.cfg.xml) 映射配置 说明
Hibernate.cfg.xml 主配置文件中主要配置:数据库连接信息.其他参数.映射信息! 常用配置查看源码: hibernate-distribution-3.6.0.Final\project ...
- 在配置hibernate.cfg.xml时需指定使用数据库的方言:
在配置hibernate.cfg.xml时需指定使用数据库的方言: 例: <property name="dialect">org.hibernate.dialect. ...
- hibernate4.3.5,Final hibernate.cfg.xml的配置
今天是接触hibernate的第二天,用来练习的是hibernate最新的版本hibernate-release-4.3.5.Final 要使用hibernate,则先要引入它的jar包,要引入的ja ...
随机推荐
- hdu 3874
求一个序列中全部数字的和,当中数值同样的仅仅能计算一次. 先储存全部的请求,然后依照它们的右边界排序,在查询的同一时候更新区间.这里事实上有一点点DP的味道,在它进行某个查询之前,保证全部的反复数字( ...
- VS2012使用XListCtrl
XListCtrl.强大ListCtrl.到现在,所有我曾经遇到过ListCtrl我们使用XListCtrl攻克. XListCtrl有什么可以支持? 变化column背景颜色.尺寸.线.制作chec ...
- cfs
转自:http://www.cnblogs.com/openix/p/3254394.html 下文中对于红黑树或链表组织的就绪队列,统称为用队列组织的就绪队列. ...
- easyui datagrid 单元格编辑 即见即所得,MVC菜单维护,扫描增加
效果如图: 参见 EasyUI 官方 Demo 及文档 @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Lay ...
- MVC 5 Web编程2 -- URL映射
ASP.NET MVC 5 Web编程2 -- URL映射(路由原理) 2015-02-12 08:50 by hangwei, 704 阅读, 5 评论, 收藏, 编辑 本章将讲述ASP.NET M ...
- UC编程:通过fwrite()和write()比较标准库函数和系统调用的速度
fwrte是C标准库中提供的函数,是对write函数的扩展与封装,write则是Unix系统提供的函数.按照常理来讲,系统调用肯定比使用库快的多,但是事实正好相反 Why?原因就在于缓冲的问题,fwi ...
- Android Studio设置自己主动编project
在Eclipse自己主动编译兄弟习惯,刚搬到Android Studio.当然,错过这个功能,自己主动编译每次执行意味着更短的时间. Android Studio里面事实上也是有自己主动编译功能的,只 ...
- IIS 5.x/6.0/7.0 和 ASP.NET
原文:IIS 5.x/6.0/7.0 和 ASP.NET 本文主要介绍 3 个主要的 IIS 版本各自对 Web 请求的不同处理方式. 本文内容 IIS 5.x 和 ASP.NET IIS 6.0 和 ...
- js实现在新标签页打开页面
这种方法打开新标签页要在IE9+以上浏览器才可以! <html> <head> <meta http-equiv="Content-type" con ...
- SD卡FAT32获得高速的文件格式(图文介绍)
说明: MBR :Master Boot Record ( 主引导记录) DBR :DOS Boot Record ( 引导扇区) FAT :File Allocation Table ( 文件分配表 ...