在eclipse中运行Hibernate实例

在eclipse中运行Hibernate实例

(一)基本环境:
SQL Server 2000
eclipse 3.0
hibernate2.1.4


(二)我的环境准备:
1。SQL Server 2000
 帐号:sa 密码:123456
 新建数据库:hibernate

2。解压hibernate-2.1.4.zip
 我的解压到了E:/javasoft/hibernate-2.1,hibernate-2.1.4.zip的解压位置可以任意,这里列出来只是为了方便叙述
 在后文中我把E:/javasoft/hibernate-2.1称之为:$Hibernate_Home
 我们将要运行的实例就在 $Hibernate_Home/eg中

3。SQL Server 2000 JDBC 驱动
 我的驱动程序在位置是:E:/javasoft/j2sdk1.4.2_04/jre/lib/ext/jtds-0.8-rc1.jar


(三)下面开始了
1。在eclipse下新建一个Java Project:TestHibernate
2。右键点击TestHibernate,在菜单中选“Properties”->“Java Build Path”->“Add External JARs”
 需要加入JAR文件列表如下:
  jtds-0.8-rc1.jar                                 E:/javasoft/j2sdk1.4.2_04/jre/lib/ext/jtds-0.8-rc1.jar
  hibernate2.jar                                    $Hibernate_Home/hibernate2.jar
  cglib-full-2.0.1.jar                              $Hibernate_Home/lib/cglib-full-2.0.1.jar
  commons-collections-2.1.jar              $Hibernate_Home/lib/commons-collections-2.1.jar
  commons-logging-1.0.3.jar                $Hibernate_Home/lib/commons-logging-1.0.3.jar
  dom4j-1.4.jar                                    $Hibernate_Home/lib/dom4j-1.4.jar
  ehcache-0.7.jar                                  $Hibernate_Home/lib/ehcache-0.7.jar
  jta.jar                                                 $Hibernate_Home/lib/jta.jar
  log4j-1.2.8.jar                                    $Hibernate_Home/lib/log4j-1.2.8.jar
  odmg-3.0.jar                                      Hibernate_Home/lib/odmg-3.0.jar

3。导入实例$Hibernate_Home/eg到TestHibernate/src下

4。导入hibernate.properties和log4j.properties到TestHibernate/src下,这两个文件在$Hibernate_Home/src下可以找到

文件结构如图:

                            

 

5。配置hibernate.properties
 在hibernate.properties中默认的数据库是HypersonicSQL,把它们全部注释掉,
 如下:
  #hibernate.dialect net.sf.hibernate.dialect.HSQLDialect
  #hibernate.connection.driver_class org.hsqldb.jdbcDriver
  #hibernate.connection.username sa
  #hibernate.connection.password
  #hibernate.connection.url jdbc:hsqldb:hsql://localhost
  #hibernate.connection.url jdbc:hsqldb:test
  #hibernate.connection.url jdbc:hsqldb:.


 找到
  ## MS SQL Server

  #hibernate.dialect net.sf.hibernate.dialect.SQLServerDialect
  #hibernate.connection.username sa
  #hibernate.connection.password sa

  ## JSQL Driver
  #hibernate.connection.driver_class com.jnetdirect.jsql.JSQLDriver
  #hibernate.connection.url jdbc:JSQLConnect://1E1/test

 修改为
  ## MS SQL Server

  hibernate.dialect net.sf.hibernate.dialect.SQLServerDialect
  hibernate.connection.username sa
  hibernate.connection.password 123456

  ## JSQL Driver
  hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver
  hibernate.connection.url jdbc:jtds:sqlserver://localhost:1433/hibernate 


6。好了,可以运行这个实例了

你可能感兴趣的:(Java)