TOMCAT 6.0.14 DBOC 安裝記錄

12月 17, 2007

緣起: 我發現TOMCAT 討論區的資料都有些過時了. 絕少有論論新版的DBOC 的安裝方法. 繞了好大一圈查了不少心得分享(大部份是舊的), 實在解決不了問題.

先說說我的安裝過程好了. 我是依循官方的文件做的.但是畢竟是官方文件. 有些小細節是沒有提及的. 不過還是請各位參考一下. 以下是官方網站的連結.

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

要特別注意這段話:
Please note that JNDI resource configuration changed somewhat between Tomcat 5.0.x and Tomcat 5.5.x. You will most likely need to modify older JNDI resource configurations to match the syntax in the example below in order to make them work in Tomcat 6.x.x.

當然光看完這段話也是一頭霧水.解決不了問題. 接下來請看看這段的說明
http://wiki.apache.org/tomcat/FAQ/Deployment
其中提到:
Why does tomcat 5 create context configuration files?

Unlike tomcat 4.x, tomcat 5.x creates context configuration files for you in its conf/[Engine name]/[Host name] directory. This is part of the change in tomcat's configuration mechanism from version 4.x to make overall configuration more robust, flexible, and enterprise-friendly. Note, however, that this has changed the recommended deployment practices for web applications. These context configuration files are created by tomcat, but not removed by tomcat, because the user may have changed them or other files in the conf directory. The suggested practice for tomcat 5 is to place context configuration files in the META-INF/context.xml directory of your webapp, and use Tomcat's Manager webapp to deploy/undeploy your applications. More details can be found here: [WWW] MARC Archive

也就是說原本在5.5版 .... 原本是被放在 c:\tomcat \conf\Server.xml 現在到了 6.0 卻被移出到 c:\tomcat\webapps\META-INF 並獨立出來為一單一的 context.xml 檔案

接下來請回到http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html 繼續看下去.
MySQL DBCP Example

0. Introduction
這部份改一下. 我的測試平台跟sample 有點不一樣.
MySQL 5.0.45
Connector/J 5.1.5 (the official JDBC Driver)mysql-connector-java-5.1.5-bin.jar
tomcat 6.0.14
Product Version: NetBeans IDE 6.0 (Build 200711261600)
Java: 1.6.0_03; Java HotSpot(TM) Client VM 1.6.0_03-b05
System: Windows XP version 5.1 running on x86; MS950; zh_TW (nb)
Userdir: C:\Documents and Settings\yitafan\.netbeans\6.0

1. MySQL configuration
這部份沒什麼特別的. 請你把它改為自己mysql server 上面的有效帳號就好

2.2. Context configuration

Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to your Context.
這裏就要注意了 要把這下列的sample 貼到
c:\tomcat\webapps\META-INF\context.xml

3. web.xml configuration

Now create a WEB-INF/web.xml for this test application.
這部份也是把官網的sample 搬到你的 c:\tomcat\webapps\WEB-INF\web.xml

4. Test code

Now create a simple test.jsp page for use later.
這個測試用的 test.jsp 就放到 c:\tomcat\webapps

這部份有用到JSTL 請使用 jakarta-taglibs-standard-1.1.2
解壓縮後,把LIB目錄下的jstl.jar 跟 standard.jar 丟到 C:\tamcat\webapps\WEB-INF\LIB 目錄下即可

注意事項. 以上目錄只是便於說明 c:\tamcat\webapps 請自行換置成您的安裝路徑. 至於 webapps 我是用官方sample的預設DBTest

後記: 跑是跑起來了 不過.我不知如何查看DBOC 連結池的狀態. 有懂這方面的朋友們.再麻煩你們指點了. 若我的解說有什麼疑問也請留言. 我會就我所了解的來跟您解釋. 若有錯誤請不吝指教
Read more

DBDesigner 4 on the Mysql 5.0.45

DBDesigner 4 這套軟體. 算是一套Free ER Diagram 程式. 在Windows 下搭配Mysql 5.0.45 卻會無法使用.
原因如下:

因為DBDesigner4 的設計者當初是以 Version 3.xx 的Mysql 作為參考. 對於帳號密碼的認證依然是採用舊的方式. 因此必需在Mysql 命令列下做點小修改.

Ok thought I would have a look at DBDesigner4 as MyWorkbench seems to be taking a long time to get into beta. DBDesigner4 looks a great product but couldnt get it to connect to mysql 5 then realised that it the designer was designed for version 3 mysql and lots of the old mysql products need to read the myql.user table for id's etc.

Tried the old trick of using the OLD_PASSWORD function and seems to work what you need to do is this....

1. Open the mysql command prompt.

2. SET PASSWORD FOR 'root'@'localhost' = OLD_PASSWORD('rootpassword');

UPDATE mysql.user SET Password = OLD_PASSWORD('rootpassword') WHERE Host = 'localhost' AND User = 'root';

FLUSH PRIVILEGES;

all in one line - hit return.

3. Try dbdesigner4 again and you should now be able to connect.

要注意以下的第二部份. 若您用選取.再用貼上的. 會出現一個問題 就是沒法子貼那麼多行的命令,
而會被強迫斷行並送出Enter 而產生錯誤. 最好是先執行前兩行命令, 沒出錯後再貼FLUSH PRIVILEGES; 來更新權限

上述原文出處:http://www.paulfarrow.com/archive/2007/09/03/dbdesigner4-windows-and-mysql-5.aspx
Read more