在OpenCMS中使用自己的数据库

修改/webapps/opencms/WEB-INF/config/opencms.properties文件,首先添加对Northwind数据库的描述

即修改

# Declaration of database pools db.pools=default

# Declaration of database pools db.pools=default,Northwind

然后添加对Northwind的描述。如下:

# # Configuration of the default database pool ################################################################################# # name of the JDBC driver db.pool.Northwind.jdbcDriver=net.sourceforge.jtds.jdbc.Driver # URL of the JDBC driver db.pool.Northwind.jdbcUrl=jdbc:jtds:sqlserver://localhost:1433/Northwind # optional parameters for the URL of the JDBC driver db.pool.Northwind.jdbcUrl.params= # user name to connect to the database db.pool.Northwind.user=sa # password to connect to the database db.pool.Northwind.password=123qwe # the URL to make the JDBC DriverManager return connections from the DBCP pool db.pool.Northwind.poolUrl=opencms:Northwind # the maximum number of objects that can be borrowed from the pool db.pool.Northwind.maxActive=25 # the maximum amount of time before throwing an exception when the pool is exhausted db.pool.Northwind.maxWait=2000 # the minimum number of objects that will kept connected db.pool.Northwind.minIdle=3 # the maximum number of objects that can sit idled in the pool db.pool.Northwind.maxIdle=10 # action to take when the pool is exhausted {grow|block|fail} db.pool.Northwind.whenExhaustedAction=block # connections will be validated before they are borrowed from the pool db.pool.Northwind.testOnBorrow=false # connections will be validated by evictor thread db.pool.Northwind.testWhileIdle=true # number of milliseconds to sleep between runs of the evictor thread # -1 means no idle connection evictor thread will be run db.pool.Northwind.timeBetweenEvictionRuns=3600000 # number of connections tested in a run of the evictor thread db.pool.Northwind.numTestsPerEvictionRun=3 # minimum amount of time in milliseconds a connection may be idle in the pool before it is eligable for eviction db.pool.Northwind.minEvictableIdleTime=1800000 # the query to validate connections #db.pool.default.testQuery=SELECT STRUCTURE_ID FROM CMS_OFFLINE_STRUCTURE WHERE RESOURCE_PATH = '/' db.pool.Northwind.testQuery= # number of attempts to connect to the database during startup (default = 10) db.pool.Northwind.connects=10 # sleep time between two attempts to connect to the database during startup in ms (default = 5000) db.pool.Northwind.wait=5000

这样就完成了对Northwind的connection pool的定义。

引用这个connection pool的实例jsp如下:

<%@page import="java.sql.*,org.opencms.db.*,org.opencms.main.*"%> <% java.sql.Connection con = OpenCms.getSqlManager().getConnection("Northwind"); Statement stmt = con.createStatement(); ResultSet rs; rs = stmt.executeQuery("SELECT LastName, FirstName FROM Employees"); while (rs.next()) { %> <%= rs.getString(1) %> <%= rs.getString(2) %><br><% } rs.close(); stmt.close(); con.close(); %>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值