在jpivot 应用程序的 jsp 文件中使用的数据库数SqlServer,mysql以及Oracle三种最常用了,现在我将自己练习MDX语法时用到的三种配置列出来:
SqlServer Jtds 数据源配置:
<jp:mondrianQuery id="query01"
catalogUri="/WEB-INF/queries/tezz.xml"
jdbcDriver="net.sourceforge.jtds.jdbc.Driver"
jdbcUrl="jdbc:jtds:sqlserver://localhost:1433/tezz"
jdbcUser="sa" jdbcPassword="123">
< 你的 MDX 语句 >
</jp:mondrianQuery>
Mysql 数据源配置:
<jp:mondrianQuery id="query01"
jdbcDriver="com.mysql.jdbc.Driver"
jdbcUrl="jdbc:mysql://localhost:3306/tezz?user=root&password=root"
catalogUri="/WEB-INF/queries/tezz.xml" >
< 你的 MDX 语句 >
</jp:mondrianQuery>
Oracle 数据源配置:
<jp:mondrianQuery id="query01"
jdbcDriver="oracle.jdbc.driver.OracleDriver"
jdbcUrl="jdbc:oracle:thin:joyque1/joyque1@192.168.0.60:1521:orcl"
catalogUri="/WEB-INF/joyqueQuery/show.xml" >
< 你的 MDX 语句 >
</ jp:mondrianQuery >
之前自己在学MDX语法时每个 jpivot 应用程序的 jsp 文件中都设置了上面的三种数据源配置, 太繁琐了,现在知道了为了简化可以进行如下配置:
1. 首先在安装目录下的 lib 文件(如: C:\tomcat6\lib )添加你所选择的数据库的驱动包
ojdbc14.jar ----Oracle 的驱动包
jtds-1.2.jar -----SqlServer 的驱动包
mysql-connector-java-5.0.4-bin.jar -----Mysql 的驱动包
3个驱动包我已上传,有需要的可以下载。
2. 在你 Tomcat 的安装目录下的 conf 文件夹下(如: C:\tomcat6\conf ),找到 context.xml 文件,在里面的 <contex> 标签下添加你需要的数据源,如下面设置:
<Context>
<Resource name="lyfy" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="sa"
password="123456"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://192.168.0.177:1433;databaseName=lydf_dw"/>
<Resource name="tezzDS" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/tezz"/>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
</Context>
如果你的 Tomcat 版本为 6.0 以上就可以跳过第 3 步,直接进行第 4 步:
3. 在项目中的 WEB-INF 下的 web.xml 中引用数据源:
<resource-ref>
<description>JPivot DBConnection</description>
<res-ref-name> tezzDS </res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4. 最后在 jpivot 应用程序的 jsp 文件中引入我们的连接池:
将数据源配置在 Tomcat 的配置文件 context.xml 里之后,页面数据源代码只需要使用“ dataSource = " 你起的配置源名称 " ”,即页面就可简化为:
test.jsp
<jp:mondrianQuery id="query01"
catalogUri="/WEB-INF/queries/tezz.xml"
dataSource=" tezzDS ">
with member [measures].[占总价比例] as
'([Measures].[Total Sale] /([Measures].[Total Sale],[Product Category].[All Products]))',
format_string = IIf(([Measures].[占总价比例] < 0.20), "|#,##0.000%|style='yellow'",
"|#,##0.00%|arrow='none'" ))
SELECT {[Measures].[Total Sale],[measures].[占总价比例]} ON COLUMNS ,
{ [Product Category].[All Products]} ON ROWS
FROM [Sales]
</jp:mondrianQuery>