Hibernate配置連線SQL SERVER2000

xuehongliang發表於2007-06-29
今天做了一個用hibernate連線sql server2000資料庫的程式,遇到了一些問題,在經過一個多小時的除錯下終於解決了.將解決問題方法在這裡記錄一下備以後查閱:

問題出現的原因就是用微軟提供的jar包.在hibernate.cfg.xml檔案中也是按照該包的配置方法進行配置,結果總是出錯,具體的出錯資訊就是找不到jar包裡的方法.於是把錯誤訊息到網上查詢,在一個帖子上發現最好不要用微軟提供的jar包,用jtds.jar.於是就上網查詢jtds.jar的下載網址,找到後下載部署的工程中.

接下來就是按照jtds.jar的檔案方式進行配置hibernate.cfg.xml檔案了.配置如下:

xml 程式碼
  1. <!--sp--&gtxml version='1.0' encoding='utf-8'?>
  2. <!--CTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
  3. ">
  4. <hibernate-configuration>
  5. <session-factory>
  6. <!-- properties --&gt
  7. <!-- define query language constants / function names --&gt
  8. <property name="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'property>
  9. <!--JNDI Datasource --&gt
  10. <!-- property name="hibernate.connection.datasource">java:comp/env/jdbc/docMgrDS
  11. <!-- SqlServer--&gt
  12. <property name="dialect">net.sf.hibernate.dialect.SQLServerDialectproperty>
  13. <!-- net.sf.hibernate.dialect.OracleDialect--&gt
  14. <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driverproperty>
  15. <!-- oracle.jdbc.driver.OracleDriver--&gt
  16. <property name="hibernate.connection.url">jdbc:jtds:sqlserver://10.64.86.34:1433/eipproperty>
  17. <!-- jdbc:oracle:thin:@192.168.3.6:1521:orcl--&gt
  18. <property name="hibernate.connection.username">saproperty>
  19. <property name="hibernate.connection.password">capinfoproperty>
  20. <!-- Hibernate Connection Pool --&gt
  21. <property name="connection.pool_size">2property>
  22. <property name="statement_cache.size">25property>
  23. <!-- property name="connection.provider_class">net.sf.hibernate.connection.DatasourceConnectionProvider
  24. <property name="connection.provider_class">net.sf.hibernate.connection.DriverManagerConnectionProviderproperty>
  25. <!-- the Transaction API abstracts application code from the underlying JTA or JDBC transactions --&gt
  26. <property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactoryproperty>
  27. <!-- print all generated SQL to the console --&gt
  28. <property name="show_sql">trueproperty>
  29. <!-- set the JDBC fetch size --&gt
  30. <property name="jdbc.fetch_size">50property>
  31. <!-- set the maximum JDBC 2 batch size (a nonzero value enables batching) --&gt
  32. <property name="jdbc.batch_size">25property>
  33. <!-- enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default) --&gt
  34. <property name="hibernate.jdbc.use_scrollable_resultset">falseproperty>
  35. <!-- use streams when writing binary types to / from JDBC --&gt
  36. <property name="jdbc.use_streams_for_binary">trueproperty>
  37. <!-- enable outerjoin fetching (specifying a Dialect will cause Hibernate to use sensible default) --&gt
  38. <property name="use_outer_join">trueproperty>
  39. <!-- --&gt
  40. <property name="max_fetch_depth">1property>
  41. <!-- --&gt
  42. <property name="cache.provider_class">net.sf.hibernate.cache.HashtableCacheProviderproperty>
  43. <!-- --&gt
  44. <property name="hibernate.cache.use_query">trueproperty>
  45. <!-- Mapping files --&gt
  46. <!-- usersys --&gt
  47. <mapping resource="com/capinfo/edu/usersys/UserObject.hbm.xml" />
  48. session-factory>
  49. hibernate-configuration>

配置成功,進行程式,哦了!

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/800861/viewspace-922098/,如需轉載,請註明出處,否則將追究法律責任。

相關文章