使用sqlsever 2000資料庫資料源來做執行個體講解,帆軟報表FineReport資料連接配接中Jboss配置JNDI大概的過程和WEBSPHERE以及WEBLOGIC基本相同,用JDBC連接配接資料庫制作報表,然後在資料庫連接配接裡将連接配接方式改成JNDI,然後在Jboss伺服器中配置好JNDI資源,然後配置釋出即可,本章節主要說明在後兩步如何配置。
在jboss\server\default\deploy下建立檔案夾,名為WebReport.war(也可通過将其打成war包來部署,這裡不做讨論),将% FR_HOME%\WebReport檔案夾下的WEB-INF複制到 WebReport.war中,然後配置好WEB-INF檔案夾下的web.xml。
将sqlsever 2000資料庫的JDBC驅動msbase.jar、mssqlserver.jar和msutil.jar三個檔案拷貝到Jboss安裝目錄下的 %JBOSS_HOME%\server\default\lib下。
在Jboss\server\default\deploy檔案夾下建立mssql-ds.xml檔案,檔案具體内容如下(可使用記事本建立):
1. <?xml version='1.0' encoding='UTF-8' ?>
2. <datasources>
3. <local-tx-datasource>
4. <jndi-name>MSSQL</jndi-name>
5. <connection-url>jdbc:microsoft:sqlserver://192.168.100.112:1433;DatabaseName=test</connection-
6. url>
7. <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
8. <user-name>sa</user-name>
9. <password>dba</password>
10. <!-- sql to call when connection is created
11. <new-connection-sql>some arbitrary sql</new-connection-sql>
12. -->
13. <!-- sql to call on an existing pooled connection when it is obtained from pool
14. <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
15. -->
16. <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional)
17. -->
18. <metadata>
19. <type-mapping>MS SQLSERVER2000</type-mapping>
20. </metadata>
21. </local-tx-datasource>
22. </datasources>
注意:其中MSSQL是對應jndi的名字,可随意改變。192.168.100.112是測試用的伺服器ip,根據實際情況設定。test是資料庫名字,mssql-ds.xml隻是對應sqlsever伺服器的檔案,如果是其他資料庫要對應生成不同的xml檔案。在jboss\docs\examples\jca路徑中有相對應各個不同伺服器的xml檔案,隻需在其基礎上做修改即可用
在以前部署的WebReport.war/web-inf檔案夾中建立Jboss-web.xml,具體内容如下:
1. <?xml version='1.0' encoding='UTF-8' ?>
2. <!DOCTYPE jboss-web
3. PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"
4. "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
5. <jboss-web>
6. <resource-ref>
7. <res-ref-name>MSSQL</res-ref-name>
8. <res-type>javax.sql.DataSource</res-type>
9. <jndi-name>java:/MSSQL</jndi-name>
10. </resource-ref>
11. </jboss-web>
其中MSSQL對應以前的jndi名字,可根據自己設定的JNDI名字來改變,其他不變。用記事本類似的工具,打開WebReport.war/WEB-INF檔案夾中的web.xml,添加内容具體如下:
1. <resource-ref>
2. <description> Resource</description>
3. <res-ref-name>MSSQL</res-ref-name>
4. <res-type>javax.sql.DataSource</res-type>
5. <res-auth>Container</res-auth>
6. </resource-ref>