開發(fā)的IDE:JBuilderX       使用的數(shù)據(jù)庫:MS Sql Server 2000       使用的數(shù)據(jù)庫驅(qū)動:JSQL Driver(JDBC 3.0)

  說明:

  1、hibernate在配置文件中明確說明“Microsoft Driver (not recomm " /> 一道本视频在线,av黄色网址,每日更新在线观看av

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

JBuilderX+SQL Server開發(fā)hibernate

環(huán)境:

   開發(fā)的IDE:JBuilderX
  
   使用的數(shù)據(jù)庫:MS Sql Server 2000
  
   使用的數(shù)據(jù)庫驅(qū)動:JSQL Driver(JDBC 3.0)

  說明:

  1、hibernate在配置文件中明確說明“Microsoft Driver (not recommended!)”,因此先使用JSQL Driver。
  
  2、JSQL Driver可以到http://www.jNETdirect.com中得到,需要先注冊個(gè)用戶,才能下載到試用的版本。

  3、JDBC3.0只能在JDK1.4及以上版本中使用,JBuilderX默認(rèn)的是JDK1.4

  準(zhǔn)備工作:

  1、下載Hibernate,目前最高版本是2.1.2

  2、在JBuilder中創(chuàng)建一個(gè)lib,起名為hibernate_full,將hibernatelib下的所有jar通通放進(jìn)去,并將hibernatehibernate2.jar也放進(jìn)去

  3、在JBuilder中創(chuàng)建一個(gè)lib,起名為JSQL3,將JSQL Driver下的JNETDirectJSQLConnectJDBC_3.0_DriverJSQLConnect.jar放進(jìn)去

  開始進(jìn)行例子:
  
  1、創(chuàng)建一個(gè)project,命名為testhibernate

  2、在屬性里的Required Libraries里加入hibernate_full和JSQL3

  3、在菜單Project --> Project Properties --> Build --> Resource 里選中xml文件,選擇“Copy” --在編譯該項(xiàng)目的時(shí)候,會自動將src文件夾里的xml文件拷貝到classes文件夾里的相應(yīng)目錄下

  4、在testhibernate項(xiàng)目中創(chuàng)建一個(gè)src目錄

  5、將hibernate源文件里的hibernatesrchibernate.properties 和 log4j.properties拷貝到testhibernate項(xiàng)目中的src目錄下

  6、修改hibernate.properties中關(guān)于MS Sql Server 2000驅(qū)動方面的配置

  找到

  ## 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:.

  這段,這里是說默認(rèn)的是使用HypersonicSQL,我們使用的是MS Sql Server,因此將整段注釋掉

  ## 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

  這段,比如我們使用的數(shù)據(jù)庫服務(wù)器機(jī)器名為yuj,數(shù)據(jù)庫名為testhi,連接到數(shù)據(jù)庫上去的用戶名為sa,密碼為sa,則修改后這段成為

  ## 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://yuj/testhi

  7、創(chuàng)建一個(gè)類testhibernate.Person,這是個(gè)標(biāo)準(zhǔn)的JavaBean,只有3個(gè)屬性和相應(yīng)的getset方法

  package testhibernate;

  public class Person
  {
  private String id;
  private String name;
  private String address;

  public void setId(String value)
  {
  this.id = value;
  }

  public String getId()
  {
  return id;
  }

  public void setName(String value)
  {
  this.name = value;
  }

  public String getName()
  {
  return name;
  }

  public void setAddress(String value)
  {
  this.address = value;
  }

  public String getAddress()
  {
  return address;
  }
  }

   8、創(chuàng)建一個(gè)對象-關(guān)系映射的xml文件Person.hbm.xml,放在和Person.Java相同的目錄下面

  <?xml version="1.0" encoding="GB2312"?>
  <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.NET/hibernate-mapping-2.0.dtd" >
  <hibernate-mapping>
  <class name="testhibernate.Person">
  <!--hibernate為我們生成主鍵id-->
  <id name = "id" unsaved-value = "null">
   <generator class="uuid.hex"/>
  </id>

  <!--默認(rèn)把類的變量映射為相同名字的表列,當(dāng)然我們可以修改其映射方式-->
  <property name="name"/>
  <property name="address"/>
  </class>
  </hibernate-mapping>

  9、創(chuàng)建調(diào)用類Person的客戶端程序Client1.Java

  package testhibernate;

  import NET.sf.hibernate.Session;
  import NET.sf.hibernate.Transaction;
  import NET.sf.hibernate.SessionFactory;
  import NET.sf.hibernate.cfg.Configuration;
  import NET.sf.hibernate.tool.hbm2ddl.SchemaExport;

  /**
  *本類只是用來創(chuàng)建表的,并不往表內(nèi)部插入任何數(shù)據(jù),并且只能使用一次,否則會刪除已有的表的
  */
  public class Client1
  {
  private static SessionFactory sessionFactory;

  public static void main(String[] args) throws Exception
  {
  Configuration conf = new Configuration().addClass(Person.class);

  //第一次運(yùn)行時(shí)用來在數(shù)據(jù)庫中創(chuàng)建表
  //并且把sql語句輸出到txt文件用的
  //以后的運(yùn)行不能使用該段代碼,否則每次都會先刪除原表,再新建該表
  SchemaExport dbExport = new SchemaExport(conf);
  dbExport.setOutputFile("sql.txt");
  dbExport.create(true, true);
  }
  }

  package testhibernate;

  import NET.sf.hibernate.Session;
  import NET.sf.hibernate.Transaction;
  import NET.sf.hibernate.SessionFactory;
  import NET.sf.hibernate.cfg.Configuration;
  import NET.sf.hibernate.tool.hbm2ddl.SchemaExport;

  public class Client2
  {
  private static SessionFactory sessionFactory;

  public static void main(String[] args) throws Exception
  {
  Configuration conf = new Configuration().addClass(Person.class);
  sessionFactory = conf.buildSessionFactory();
  Session s = sessionFactory.openSession();

  Transaction t = s.beginTransaction();

  Person yuj = new Person();
  yuj.setName("john");
  yuj.setAddress("上海");

  Person x = new Person();
  x.setName("zhaoyh");
  x.setAddress("上海");

  //持久化
  s.save(yuj); //此時(shí)yuj已經(jīng)可以在數(shù)據(jù)庫中找到
  s.save(x); //此時(shí)x已經(jīng)可以在數(shù)據(jù)庫中找到

  t.commit();
  s.close();
  }
  }

  查看數(shù)據(jù)庫中,增加了2條記錄,OK!初步使用成功了,剩下的慢慢研究吧……

jsp技術(shù)JBuilderX+SQL Server開發(fā)hibernate,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 电影痴人之爱| china中国农村妇女aⅴ| 雾里简谱| 女生操| 来5566看av激情电影使劲撸| 搜狐视频官网| lanarhoades在线av| 李轻扬| 探究事物的本质的读后感想| 新成长的烦恼| 挂耳染发图片大全| 色女综合网| 电视剧《流金岁月》演员表| 云上的宝石| 啊啊视频| 最后的招待1991| 秦皇岛电视台| 瑜伽焰口拼音版全文| 吉泽明步作品| 洞房奇谭电影免费版在线观看| 被抛弃的青春1982| 简单的应急预案怎么写| 国产伦理电影在线观看| 骆文博| 白事专用歌曲100首| 《与凤行》演员表| 莴笋是发物吗| 《美景之屋| 姐夫操小姨子| 成龙电影大全免费全集| 欧美乱淫av片免费黑鬼| 郭明翔| 美女网站视频免费| 美丽丽人| 杨紫和肖战演的电视剧是什么| 可可托海的牧羊人原唱歌曲| 搜狐网站官网| 挨饿游戏| 吴涟序| 我家来了个怪男人| 帕巴拉呼图克图|