ibatis配置文件

<p><font size="2"></font></p> <pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑">ibatis配置文件 SqlMapConfig.xml </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"></font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"></font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2"><font face="微軟雅黑"><span style="color: #0000ff">&lt;?</span>xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; <span style="color: #0000ff">?&gt;</span> </font></font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2"><font face="微軟雅黑"><span style="color: #0000ff">&lt;</span>!DOCTYPE sqlMapConfig </font></font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑">PUBLIC &quot;-//iBATIS.com//DTD SQL Map Config 2.0//EN&quot; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑">&quot;http://www.ibatis.com/dtd/sql-map-config-2.dtd&quot;<span style="color: #0000ff">&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"></font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2"><font face="微軟雅黑"><span style="color: #0000ff">&lt;</span><span style="color: #800000">sqlMapConfig</span><span style="color: #0000ff">&gt;</span> </font></font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">settings</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #ff0000">cacheModelsEnabled</span>=<span style="color: #0000ff">&quot;true&quot;</span> &lt;!-- <span style="color: #ff0000">是否啓用SqlMapClient</span> <span style="color: #ff0000">上的緩存機制</span>。<span style="color: #ff0000">建議設爲</span>&quot;<span style="color: #ff0000">true</span>&quot; --<span style="color: #0000ff">&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> enhancementEnabled=&quot;true&quot; </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- 是否針對POJO啓用字節碼加強機制以提高getter/setter的調用效能,避免使用Java Reflect所帶來的性能開銷。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 同時,這也爲Lazy Loading帶來了極大的性能提高。建議設爲&quot;true&quot; --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> lazyLoadingEnabled=&quot;true&quot; <span style="color: #008000">&lt;!-- 是否啓用延遲加載機制,建議設爲&quot;true&quot; --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> errorTracingEnabled=&quot;true&quot; <span style="color: #008000">&lt;!-- 是否啓用錯誤日誌,在開發期間建議設爲&quot;true&quot;以方便調試 --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> maxRequests=&quot;32&quot; <span style="color: #008000">&lt;!-- 最大併發請求數(Statement 併發數) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> maxSessions=&quot;10&quot; <span style="color: #008000">&lt;!-- 最大Session 數。即當前最大容許的併發SqlMapClient 數。 --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #008000">&lt;!-- maxSessions設定必須介於maxTransactions和maxRequests之間,即maxTransactions&lt;maxSessions=&lt;maxRequests --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> maxTransactions=&quot;5&quot; <span style="color: #008000">&lt;!-- 最大併發事務數 --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> useStatementNamespaces=&quot;false&quot; </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- 是否使用Statement命名空間。這裏的命名空間指的是映射文件中,sqlMap節點 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 的namespace屬性,如在上例中針對t_user表的映射文件sqlMap節點:&lt;sqlMap namespace=&quot;User&quot;&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 這裏,指定了此sqlMap節點下定義的操做均從屬於&quot;User&quot;命名空間。在useStatementNamespaces=&quot;true&quot;的情 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 況下,Statement調用需追加命名空間,如:sqlMap.update(&quot;User.updateUser&quot;,user); </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 不然直接經過Statement名稱調用便可,如:sqlMap.update(&quot;updateUser&quot;,user); </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 但請注意此時須要保證全部映射文件中,Statement定義無重名。 --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> /&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">transactionManager</span> <span style="color: #ff0000">type</span>=<span style="color: #0000ff">&quot;JDBC&quot;</span><span style="color: #0000ff">&gt;</span> <span style="color: #008000">&lt;!-- 定義了ibatis 的事務管理器 --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- SIMPLE 的配置用法 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;dataSource type=&quot;SIMPLE&quot;&gt; &lt;!-- dataSource的實現類型 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> SIMPLE:簡單的數據庫聯接池實現 實現類爲 com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactory。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> DBCP: 基於Apache DBCP 鏈接池組件實現的DataSource 封裝,當無容器提供DataSource 服務時, </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 建議使用該選項,對應ibatis 實現類爲com.ibatis.sqlmap.engine.datasource.DbcpDataSourceFactory。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> JNDI:使用J2EE 容器提供的DataSource 實現,DataSource 將經過指定的JNDI Name 從容器中獲取。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 對應ibatis 實現類爲com.ibatis.sqlmap.engine.datasource.JndiDataSourceFactory。 --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;JDBC.Driver&quot;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;com.p6spy.engine.spy.P6SpyDriver&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- JDBC 驅動。(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;JDBC.ConnectionURL&quot;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;jdbc:mysql://localhost/sample&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫URL。(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;JDBC.Username&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;user&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫用戶名(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;JDBC.Password&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;mypass&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫密碼 (SIMPLE,DBCP)--&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.MaximumActiveConnections&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;10&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫鏈接池可維持的最大容量。(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.MaximumIdleConnections&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;5&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫鏈接池中容許的掛起(idle)鏈接數。(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.MaximumCheckoutTime&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;120000&quot;</span><span style="color: #0000ff">/&gt;</span> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- 數據庫聯接池中,鏈接被某個任務所容許佔用的最大時間, </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 若是超過這個時間限定,鏈接將被強制收回。(毫秒)(SIMPLE) --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.TimeToWait&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;500&quot;</span><span style="color: #0000ff">/&gt;</span> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- 當線程試圖從鏈接池中獲取鏈接時,鏈接池中無可用鏈接可供使用, </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 此時線程將進入等待狀態,直到池中出現空閒鏈接。此參數設定了線程所允 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 許等待的最長時間。(毫秒)(SIMPLE) --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.PingQuery&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;select 1 from ACCOUNT&quot;</span><span style="color: #0000ff">/&gt;</span> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- 數據庫鏈接狀態檢測語句。某些數據庫在鏈接在某段時間持續處於空閒狀態 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 時會將其斷開。而鏈接池管理器將經過此語句檢測池中鏈接是否可用。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 檢測語句應該是一個最簡化的無邏輯SQL。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 如「select 1 from t_user」,若是執行此語句成功, </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 鏈接池管理器將認爲此鏈接處於可用狀態。(SIMPLE) --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.PingEnabled&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;false&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 是否容許檢測鏈接狀態。(SIMPLE) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.PingConnectionsOlderThan&quot;</span><span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;1&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 對持續鏈接時間超過設定值(毫秒)的鏈接進行檢測 (SIMPLE)--&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.PingConnectionsNotUsedFor&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;1&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 對空閒超過設定值(毫秒)的鏈接進行檢測。(SIMPLE) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">dataSource</span><span style="color: #0000ff">&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> --&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- DBCP 的配置用法 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;dataSource type=&quot;SIMPLE&quot;&gt; &lt;!-- dataSource的實現類型 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> SIMPLE:簡單的數據庫聯接池實現 實現類爲 com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactory。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> DBCP: 基於Apache DBCP 鏈接池組件實現的DataSource 封裝,當無容器提供DataSource 服務時, </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 建議使用該選項,對應ibatis 實現類爲com.ibatis.sqlmap.engine.datasource.DbcpDataSourceFactory。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> JNDI:使用J2EE 容器提供的DataSource 實現,DataSource 將經過指定的JNDI Name 從容器中獲取。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 對應ibatis 實現類爲com.ibatis.sqlmap.engine.datasource.JndiDataSourceFactory。 --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;JDBC.Driver&quot;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;com.p6spy.engine.spy.P6SpyDriver&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- JDBC 驅動。(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;JDBC.ConnectionURL&quot;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;jdbc:mysql://localhost/sample&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫URL。(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;JDBC.Username&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;user&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫用戶名(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;JDBC.Password&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;mypass&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫密碼 (SIMPLE,DBCP)--&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.MaximumActiveConnections&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;10&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫鏈接池可維持的最大容量。(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.MaximumIdleConnections&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;5&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫鏈接池中容許的掛起(idle)鏈接數。(SIMPLE,DBCP) --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.MaximumWait&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;1000&quot;</span><span style="color: #0000ff">/&gt;</span> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- 當線程試圖從鏈接池中獲取鏈接時,鏈接池中無可用鏈接可供使用,此時線程將進入等待狀態, </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 直到池中出現空閒鏈接。此參數設定了線程所容許等待的最長時間。(毫秒) --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">naem</span>=<span style="color: #0000ff">&quot;Pool.ValidationQuery&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;select 1 from ACCOUNT&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫鏈接狀態檢測語句。--&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.LogAbandoned&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;false&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 當數據庫鏈接被廢棄時,是否打印日誌 --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.RemoveAbandonedTimeout&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;1000&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 數據庫鏈接被廢棄的最大超時時間 --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;Pool.RemoveAbandoned&quot;</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;true&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- 當鏈接空閒時間超過RemoveAbandonedTimeout時,是否將其廢棄。--&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">dataSource</span><span style="color: #0000ff">&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> --&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- JNDI 的配置用法 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;dataSource type=&quot;JNDI&quot;&gt; &lt;!-- dataSource的實現類型 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> SIMPLE:簡單的數據庫聯接池實現 實現類爲 com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactory。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> DBCP: 基於Apache DBCP 鏈接池組件實現的DataSource 封裝,當無容器提供DataSource 服務時, </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 建議使用該選項,對應ibatis 實現類爲com.ibatis.sqlmap.engine.datasource.DbcpDataSourceFactory。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> JNDI:使用J2EE 容器提供的DataSource 實現,DataSource 將經過指定的JNDI Name 從容器中獲取。 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 對應ibatis 實現類爲com.ibatis.sqlmap.engine.datasource.JndiDataSourceFactory。 --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">property</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">&quot;DataSource&quot;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">&quot;java:comp/env/jdbc/myDataSource&quot;</span><span style="color: #0000ff">/&gt;</span> <span style="color: #008000">&lt;!-- JNDI --&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">dataSource</span><span style="color: #0000ff">&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> --&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- 使用容器提供的JTA服務實現全局事務管理。的設置 </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;transactionManager type=&quot;JTA&quot; &gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;property name=&quot;UserTransaction&quot; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> value=&quot;java:/ctx/con/UserTransaction&quot;/&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;dataSource type=&quot;JNDI&quot;&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;property name=&quot;DataSource&quot; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> value=&quot;java:comp/env/jdbc/myDataSource&quot;/&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;/dataSource&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> &lt;/transactionManager&gt; </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">transactionManager</span><span style="color: #0000ff">&gt;</span> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> <span style="color: #0000ff">&lt;</span><span style="color: #800000">sqlMap</span> <span style="color: #ff0000">resource</span>=<span style="color: #0000ff">&quot;com/ibatis/sample/User.xml&quot;</span><span style="color: #0000ff">/&gt;</span> </font><span style="color: #008000"><font size="2" face="微軟雅黑">&lt;!-- sqlMap 節點指定了映射文件的位置,配置中可出現多個sqlMap 節點, </font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"> 以指定項目內所包含的全部映射文件。 --&gt;</font></span> </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2" face="微軟雅黑"></font></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 10px"><font size="2"><font face="微軟雅黑"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">sqlMapConfig</span><span style="color: #0000ff">&gt;</span></font></font></pre></pre>java

相關文章
相關標籤/搜索