<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "JForum 改用 DataSource 連線資料庫"]]></title>
		<link>https://forum.andowson.com/posts/list/7.page</link>
		<description><![CDATA[Latest messages posted in the topic "JForum 改用 DataSource 連線資料庫"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>JForum 改用 DataSource 連線資料庫</title>
				<description><![CDATA[ 1.編輯server.xml，加入&lt;Resource&gt;到&lt;Context&gt; 
<br>
[code=xml] 
<br>
 &lt;Context path="" docBase="webapps/forum.mycompany.com" debug="0" reloadable="false"&gt; 
<br>
 &lt;Resource name="jdbc/JForumDB" auth="Container" 
<br>
 type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@(description=(ENABLE=BROKEN)(load_balance=on)(FAILOVER_MODE=(RETRIES=20)(DELAY=15))(address=(protocol=tcp)(host=LISTENER_DB1)(port=1521))(address=(protocol=tcp)(host=LISTENER_DB2)(port=1521))(connect_data=(service_name=racdb)))" 
<br>
 username="jforum" password="jforum" maxActive="100" maxIdle="1" 
<br>
 maxWait="-1" removeAbandoned="true" removeAbandonedTimeout="60" 
<br>
 logAbandoned="true"/&gt; 
<br>
 &lt;/Context&gt; 
<br>
[/code] 
<br>
<br>
其中LISTENER_DB1和LISTENER_DB2已經在/etc/hosts設定好對應到兩部資料庫的主機IP。 
<br>
<br>
2.編輯WEB-INF/web.xml，加入&lt;resource-ref&gt;： 
<br>
[code=xml] 
<br>
 &lt;resource-ref&gt; 
<br>
 &lt;description&gt;DB Connection&lt;/description&gt; 
<br>
 &lt;res-ref-name&gt;jdbc/JForumDB&lt;/res-ref-name&gt; 
<br>
 &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; 
<br>
 &lt;res-auth&gt;Container&lt;/res-auth&gt; 
<br>
 &lt;/resource-ref&gt; 
<br>
[/code] 
<br>
<br>
3.修改WEB-INF/config/jforum-custom.conf，將database.connection.implementation改為net.jforum.DataSourceConnection，並加入database.datasource.name這個key，並設定其值為java:/comp/env/jdbc/JForumDB。接著我們可以把其他database開頭的資料庫連線相關設定key一併刪除，完成後看起來就像下面的樣子： 
<br>
[code] 
<br>
... 
<br>
dao.driver=net.jforum.dao.oracle.OracleDataAccessDriver 
<br>
database.connection.implementation=net.jforum.DataSourceConnection 
<br>
database.datasource.name=java:/comp/env/jdbc/JForumDB 
<br>
database.driver.name=oracle 
<br>
database.support.autokeys=false 
<br>
database.support.subqueries=true 
<br>
... 
<br>
[/code] 
<br>
<br>
4.複製WEB-INF/lib/下的資料庫JDBC Driver到Tomcat的common/lib下，例如ojdbc14.jar。 
<br>
<br>
5.重新啟動Tomcat 
<br>
<br>
6.連線到討論區網站首頁，如果正常顯示即OK。 
<br>
<br>
參考資料： 
<br>
http://www.jforum.net/posts/list/1363.page 
<br>
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/225/341.page</guid>
				<link>https://forum.andowson.com/posts/preList/225/341.page</link>
				<pubDate><![CDATA[Sat, 8 Mar 2008 01:37:04]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
	</channel>
</rss>