開發的IDE:JBuilderX       使用的數據庫:MS Sql Server 2000       使用的數據庫驅動:JSQL Driver(JDBC 3.0)

  說明:

  1、hibernate在配置文件中明確說明“Microsoft Driver (not recomm " /> 免费aⅴ视频,国产成人综合久久亚洲精品,在线欧美日韩

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

JBuilderX+SQL Server開發hibernate

環境:

   開發的IDE:JBuilderX
  
   使用的數據庫:MS Sql Server 2000
  
   使用的數據庫驅動:JSQL Driver(JDBC 3.0)

  說明:

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

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

  準備工作:

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

  2、在JBuilder中創建一個lib,起名為hibernate_full,將hibernatelib下的所有jar通通放進去,并將hibernatehibernate2.jar也放進去

  3、在JBuilder中創建一個lib,起名為JSQL3,將JSQL Driver下的JNETDirectJSQLConnectJDBC_3.0_DriverJSQLConnect.jar放進去

  開始進行例子:
  
  1、創建一個project,命名為testhibernate

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

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

  4、在testhibernate項目中創建一個src目錄

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

  6、修改hibernate.properties中關于MS Sql Server 2000驅動方面的配置

  找到

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

  這段,這里是說默認的是使用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

  這段,比如我們使用的數據庫服務器機器名為yuj,數據庫名為testhi,連接到數據庫上去的用戶名為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、創建一個類testhibernate.Person,這是個標準的JavaBean,只有3個屬性和相應的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、創建一個對象-關系映射的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>

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

  9、創建調用類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;

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

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

  //第一次運行時用來在數據庫中創建表
  //并且把sql語句輸出到txt文件用的
  //以后的運行不能使用該段代碼,否則每次都會先刪除原表,再新建該表
  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); //此時yuj已經可以在數據庫中找到
  s.save(x); //此時x已經可以在數據庫中找到

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

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

jsp技術JBuilderX+SQL Server開發hibernate,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 国内精品久久久久影院不卡 | 国产成人在线看 | 91成年人| 色天天天天 | 国产午夜人做人免费视频中文 | 999精品免费视频 | 天天操夜夜做 | 午夜久久久久久网站 | 亚洲国产成人久久午夜 | 国产高清视频免费人人爱 | 欧美一区二区三区gg高清影视 | 精品国产午夜久久久久九九 | 欧美精品成人一区二区视频一 | 色综合久久综合欧美综合图片 | 国语自产免费精品视频在 | 国产精品久久久香蕉 | 成人免费视频网 | 爱搞逼综合网 | 欧美色呦呦 | 四虎在线最新永久免费播放 | 中国美女牲交一级毛片 | 激情六月婷婷开心丁香开心 | 中文字幕一区在线观看视频 | 一区二区三区四区视频在线观看 | 亚洲视频欧洲视频 | 国产亚洲精品拍拍拍拍拍 | 欧美人与物另类 | 国产成人啪精品午夜在线播放 | 永久黄网站色视频免费 | 免费91麻豆精品国产自产在线观看 | 伊人免费视频二 | 久久激情网 | 六月色天 | 美女国产在线观看免费观看 | 国产精品27页 | 蕾丝视频福利网站 | 欧美黄区 | 国产亚洲精彩视频 | 国产91久久精品一区二区 | 91色网站| 日美女网站 |