说明:本例采用myeclipse+sqlserver2000
 hibernate版本为3.0.
 数据库驱动为:jtds-1.0.2。

1。配置myeclipse环境(eclipse-SDK-3.1.1+myeclipse4.1.1GA_E3.1)。
2.配置好sqlserver2000数据库:建立数据库:goto  . 表 test_products

CREATE TABLE [dbo].[test_products] ( [id] [int] IDENTITY (1, 1) NOT NULL , [aotoid] [char] (50) COLLATE Chinese_PRC_CI_AS NULL , [username] [char] (50) COLLATE Chinese_PRC_CI_AS NULL , [price] [int] NULL , [amount] [int] NULL )

id为自动编号。

3。新建项目--myeclipse--Web Project 。本例为:prodcast
4. 右单击prodcast,加入myeclipse的hibernate.并在此工程中建立数据连结。
建立完成后,在src下自动生成hibernate.cfg.xml,内容为:

<?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="connection.username">sa</property> <property name="connection.url">jdbc:jtds:sqlserver://192.168.1.88:1433;DatabaseName=goto
</property> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> <property name="connection.password">hcsys</property> <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> </session-factory> </hibernate-configuration>

5。建立:Product.java:

package test.hibernate; import java.io.Serializable; public class Product implements Serializable { private static final long serialVersionUID = 3858043967100350732L; private Integer id; private String aotoid; private String username; private Integer price; private Integer amount; public Integer getAmount() { return amount; } public void setAmount(Integer amount) { this.amount = amount; } public String getAotoid() { return aotoid; } public void setAotoid(String aotoid) { this.aotoid = aotoid; } public Integer getPrice() { return price; } public void setPrice(Integer price) { this.price = price; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } }

6.建立InsertProduct.java

package test.hibernate; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.*; import org.hibernate.classic.Session; public class InsertProduct { public static void main(String[] args) { SessionFactory sf = new Configuration().configure() .buildSessionFactory(); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); Product p = new Product(); p.setAotoid("1"); p.setUsername("zhang"); p.setAmount(new Integer(10)); p.setPrice(new Integer(10)); System.out.println(p+"_______________1"); try{ session.save(p); tx.commit(); session.close(); System.out.println(p+"_______________2"); }catch(Exception ex){ ex.printStackTrace(); } } }

7.在test.hibernate包下建立:Product.hbm.xml.

<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="test.hibernate"> <class table="test_products" name="Product"> <!--自动编号--> <id name="id" type="int" column="id" unsaved-value="0"> <generator class="identity"/> </id> <property name="aotoid" column="aotoid" type="string" length="50"/> <property name="username" column="username" type="string" length="50"/> <property name="price" column="price" type="int"/> <property name="amount" column="amount" type="int"/> </class> </hibernate-mapping>

8.打开hibernate.cfg.xml.加入:
 <mapping resource="hibernate.cfg.xml" />
 <mapping resource="test/hibernate/Product.hbm.xml" />
形成完整的config:

<?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="connection.username">sa</property> <property name="connection.url">jdbc:jtds:sqlserver://192.168.1.88:1433;DatabaseName=goto
</property> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> <property name="connection.password">hcsys</property> <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> <mapping resource="hibernate.cfg.xml" /> <mapping resource="test/hibernate/Product.hbm.xml" /> </session-factory> </hibernate-configuration>

myeclipse下hibernate入门实例介绍相关推荐

  1. Neo4j官方入门实例介绍

    2.4 官方入门实例介绍 本节的内容不必深入掌握,主要是给大家一个简单的认识,具体的 Cypher 语言在下一章会详细讲解. 为了方便用户入门, Neo4j Web 管理界面提供了一个官方入门实例 & ...

  2. php memcached 例子,php下Memcached入门实例解析

    本文较为详细的讲述了php下Memcached的入门知识与实例.分享给大家供大家参考.具体如下: memcache 在什么情况下被使用,什么情况下不要使用? 你在何时应该使用 memcache,又要在 ...

  3. RapidJSON入门:手把手教入门实例介绍

    RapidJSON优点 跨平台 编译器:Visual Studio.gcc.clang 等 架构:x86.x64.ARM 等 操作系统:Windows.Mac OS X.Linux.iOS.Andro ...

  4. hibernate入门实例

    参考 :http://blog.csdn.net/passion_wu128/article/details/50103513 转载于:https://www.cnblogs.com/mingzhan ...

  5. HibernateAnnotation入门实例

    1.前言 刚接触hibernate的时候,第一感觉就是麻烦,因为要使用hibernate的话,要写许许多多的.hbm.xml的配置文件,每一个pojo要写一个,然后保存着主外键关联的关系表也要写.bh ...

  6. 领峰贵金属入门知识介绍:这些知识需掌握

    现在的投资市场中,投资者还是能看到很多投资产品的存在,尤其是贵金属更是因为有一定的投资优势,因此是成为投资者会选择投资的产品.在进入贵金属市场交易之前,还是需要了解下贵金属入门知识介绍,掌握这些交易知 ...

  7. Linux WAK介绍与入门实例

    简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为 强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分 ...

  8. Hibernate基于Maven入门实例,与MyBatis比对

    此篇承接上一篇: MyBatis基于Maven入门实例 准备部分 1. 进入http://mvnrepository.com/ , 搜索 Hibernate ORM, 找到相应的版本后, 可以看到配置 ...

  9. vue2+vuex+vue-router 快速入门(三) vue 实例介绍

    vue 实例介绍 vue 实例分两种,一种为组件实例,另外一种为根实例.组件实例负责创建个性化组件.而根实例负责把组件渲染到指定的真实的 DOM 结构中.并且 vue 为我们提供了一种特殊的文件格式  ...

最新文章

  1. SQL SERVER中求上月、本月和下月的第一天和最后一天[转]
  2. Algs4-1.5.4给出id[]和sz[]的内容与次数
  3. 正确高效使用数据库不可不知的索引失效问题
  4. linux错误说未声明,如何在Linux 32位计算机上解决REG_EIP未声明(在此函数中首次使用)错误?...
  5. 两个pdf怎么打开成两个窗口_如何将图片合并成PDF?教你两个免费方法
  6. OpenDiscussion_DataDrivenDesign
  7. 交换机接口用了那几根线_交换机接口知识大全!网络从业者必懂!
  8. [转]bookmark整理之.NET编程相关
  9. Hibernate之Inverse的用法
  10. Paint方法总结(三):图层混合模式
  11. 【经典算法】第一回:快速排序
  12. 食品行业仓储条码管理系统解决方案
  13. 02:Glove论文学习
  14. GitHub远程拉取仓库项目提示Please use a personal access token instead.解决方法
  15. 【Unity】Jay 开发日志(三)——道具效果的实现(上)
  16. 【情人节表白神器:送她一个HTML动态表白网站 带源码】
  17. IT男把笔记本电脑放膝上会怎样?
  18. 区块链 - DAPP
  19. opensuse15.1 安装nvidia显卡驱动(yast一键安装)
  20. 使用自制相机运行 VINS-Mono

热门文章

  1. elasticsearch 6.1.1 transport jar
  2. 别看360完成私有化 仍有三因素阻碍中概股回归
  3. 人工智能大幕开启 安防行业已成先头部队
  4. Spring Boot集成CKFinder
  5. 计算 JS 数组中最大最小值
  6. 没有人会告诉您乘坐飞机时的几个事实 但是您一定要知道
  7. 银屑病需要的碱性食物
  8. 2017届-应届毕业生-兆芯 GPU architecture design校招在线笔试题
  9. hive启动时出现javax.jdo.JDODataStoreException: Error executing SQL query
  10. 双系统win7+ubuntu18.10在win7中读取linux下面的内容