一、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连接数据库的更多相关文章

  1. hibernate.cfg.xml常见配置

    转载自:http://blog.csdn.net/qiaqia609/article/details/9456489 <!--标准的XML文件的起始行,version='1.0'表明XML的版本 ...

  2. hibernate.cfg.xml 配置(摘录)

    配置文件中映射元素详解 对象关系的映射是用一个XML文档来说明的.映射文档可以使用工具来生成,如XDoclet,Middlegen和AndroMDA等.下面从一个映射的例子开始讲解映射元素,映射文件的 ...

  3. Hibernate 注解时 hibernate.hbm.xml的配置方法 以及与SSH整合里的配置方式

    ①纯Hibernate开发: 当你在Bean中写入注解后,需要告诉hibernate哪些类使用了注解. 方法是在hibernate.hbm.xml文件中配置 <!DOCTYPE hibernat ...

  4. hibernate.cfg.xml配置(Oracle+c3p0)

    说明:数据库:Oracle10g:连接池:c3p0 结构: 一.配置hibernate.cfg.xml <?xml version="1.0" encoding=" ...

  5. hibernate 非xml实体类配置方法!

    hibernate 非xml实体类配置方法! 这个是hibernate.cfg.xml配置文件 <?xml version='1.0' encoding='UTF-8'?> <!DO ...

  6. hibernate.cfg.xml文件的配置模板和不同数据库的配置參数

    (1)hibernate.cfg.xml文件的配置模板 <?xml version="1.0" encoding="UTF-8"?> <!DO ...

  7. Hibernate框架 主配置文件(Hibernate.cfg.xml) 映射配置 说明

    Hibernate.cfg.xml 主配置文件中主要配置:数据库连接信息.其他参数.映射信息! 常用配置查看源码: hibernate-distribution-3.6.0.Final\project ...

  8. 在配置hibernate.cfg.xml时需指定使用数据库的方言:

    在配置hibernate.cfg.xml时需指定使用数据库的方言: 例: <property name="dialect">org.hibernate.dialect. ...

  9. hibernate4.3.5,Final hibernate.cfg.xml的配置

    今天是接触hibernate的第二天,用来练习的是hibernate最新的版本hibernate-release-4.3.5.Final 要使用hibernate,则先要引入它的jar包,要引入的ja ...

随机推荐

  1. android 卸载程序、清除数据、停止服务用法

    要实现卸载程序.清除数据.停止正在执行的服务这几大模块,如今将代码粗略总结例如以下: 主要运用到的类有 PackageManager ActivityManager ApplicationInfo R ...

  2. easyui datagrid shift 多选

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta na ...

  3. Redhat Enterprise server 6.3 构造VPN

    一.软体 dkms.kernel_ppp_mppe.pptpd 二.下载软件 wget http://sourceforge.net/projects/poptop/files/mppe%20modu ...

  4. 合并多段zip文件并解压缩

    cat xxx.zip.*** >xxx.zip unzip xxx.zip

  5. 基于HTTP/2和protobuf的RPC框架:GRPC

    谷歌发布的首款基于HTTP/2和protobuf的RPC框架:GRPC Google 刚刚开源了grpc,  一个基于HTTP2 和 Protobuf 的高性能.开源.通用的RPC框架.Protobu ...

  6. LINUX下getsockopt和setsockopt函数

    这两个函数仅用于套接字. 函数原型: #include <sys/socket.h> #include <sys/types.h> int getsockopt(int soc ...

  7. c#之冒泡排序的三种实现和性能分析

    冒泡排序算法是我们经常见到的尤其是子一些笔试题中. 下面和大家讨论c#中的冒泡排序,笔者提供了三种解决方案,并且会分析各自的性能优劣. 第一种估计大家都掌握的,使用数据交换来实现,这种就不多说了,园子 ...

  8. Hibernate进化史-------Hibernate概要

    一个.Hibernate概要 什么是Hibernate呢?首先,Hibernate是数据持久层的一个轻量级框架.实现了ORMapping原理(Object Relational Mapping). 在 ...

  9. mvc4项目数据库优先的尝试

    对于mvc代码优先原则,感觉真不知道为什么硬要设计这种模式,代码优先使得每次运行程序都要重建数据库,现实中这种模式有什么用呢. 数据库优先可能有好多方式,看了好久才做出来一种比较简单的.通过先添加一个 ...

  10. ASP.NET MVC+Knockout+Web API+SignalR

    架构设计(ASP.NET MVC+Knockout+Web API+SignalR) 架构设计(ASP.NET MVC+Knockout+Web API+SignalR) 2014-01-16 18: ...