boneCp jdbc connection directly,the sql monitor can't work

223 views
Skip to first unread message

爱MM男人

unread,
Mar 24, 2012, 8:36:52 PM3/24/12
to javamelody
path:
WEB-INF/dbconfig.properties
content:
jdbc.type=mysql
jdbc.driverClassName=net.bull.javamelody.JdbcDriver
driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1/fds
jdbc.username=root
jdbc.password=123456

boneCP.idleMaxAge=10
boneCP.idleConnectionTestPeriod=10
boneCP.partitionCount=3
boneCP.acquireIncrement=10
boneCP.maxConnectionsPerPartition=10
boneCP.minConnectionsPerPartition=10
boneCP.preparedStatementCacheSize=10
boneCP.statementsCachedPerConnection=10
boneCP.releaseHelperThreads=3

javacode:
/**
* 获得数据库连接
* @return
* @throws ConfigurationException
* @throws SQLException
* @throws ClassNotFoundException
*/
public static Connection getConnection() throws
ConfigurationException, SQLException, ClassNotFoundException{
if(connectionPool==null){
connectionPool= new BoneCP(ConfigFactory.getBoneCpConfig());
}
return connectionPool.getConnection();
}
ConfigFactory.getBoneCpConfig():
/**
* 获取bonecp配置信息
* @return
* @throws ConfigurationException
* @throws ClassNotFoundException
*/
public static BoneCPConfig getBoneCpConfig() throws
ConfigurationException, ClassNotFoundException{
if(bonecpConfig==null){
bonecpConfig = new BoneCPConfig();
dbConfig=getDbConfig();
Class.forName(dbConfig.getString("jdbc.driverClassName"));
bonecpConfig.setJdbcUrl(dbConfig.getString("jdbc.url"));
bonecpConfig.setUsername(dbConfig.getString("jdbc.username"));
bonecpConfig.setPassword(dbConfig.getString("jdbc.password"));

//
bonecpConfig.setIdleMaxAge(dbConfig.getLong("boneCP.idleMaxAge"));
//
bonecpConfig.setIdleConnectionTestPeriod(dbConfig.getLong("boneCP.idleConnectionTestPeriod"));

bonecpConfig.setPartitionCount(dbConfig.getInt("boneCP.partitionCount"));

bonecpConfig.setAcquireIncrement(dbConfig.getInt("boneCP.acquireIncrement"));

bonecpConfig.setMaxConnectionsPerPartition(dbConfig.getInt("boneCP.maxConnectionsPerPartition"));

bonecpConfig.setMinConnectionsPerPartition(dbConfig.getInt("boneCP.minConnectionsPerPartition"));

bonecpConfig.setStatementsCacheSize(dbConfig.getInt("boneCP.statementsCachedPerConnection"));

bonecpConfig.setReleaseHelperThreads(dbConfig.getInt("boneCP.releaseHelperThreads"));
}
return bonecpConfig;
}

now javamelody can't monitor the sql and connections help me ,thank
you very much

Vernat Emeric

unread,
Mar 25, 2012, 6:00:27 AM3/25/12
to javam...@googlegroups.com
Hi,

As said in the user guide, when using a jdbc driver directly, the *jdbc
property* "driver" should be added with the class of the real driver for
value.

In this case, you have a property "driver" in your dbconfig.properties
file, but you do nothing with it.
I think that for BoneCP, you need to add the following lines in your
getBoneCpConfig():

Properties driverProperties = new Properties();
driverProperties.put("driver", dbConfig.getString("driver"));
bonecpConfig.setDriverProperties(driverProperties);

Let us know if this work.

bye,
Emeric


Le 25/03/2012 01:36, 锟斤拷MM锟斤拷锟斤拷 a 锟斤拷crit :


> path:
> WEB-INF/dbconfig.properties
> content:
> jdbc.type=mysql
> jdbc.driverClassName=net.bull.javamelody.JdbcDriver
> driver=com.mysql.jdbc.Driver
> jdbc.url=jdbc:mysql://127.0.0.1/fds
> jdbc.username=root
> jdbc.password=123456
>
> boneCP.idleMaxAge=10
> boneCP.idleConnectionTestPeriod=10
> boneCP.partitionCount=3
> boneCP.acquireIncrement=10
> boneCP.maxConnectionsPerPartition=10
> boneCP.minConnectionsPerPartition=10
> boneCP.preparedStatementCacheSize=10
> boneCP.statementsCachedPerConnection=10
> boneCP.releaseHelperThreads=3
>
> javacode:
> /**

> * 锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷


> * @return
> * @throws ConfigurationException
> * @throws SQLException
> * @throws ClassNotFoundException
> */
> public static Connection getConnection() throws
> ConfigurationException, SQLException, ClassNotFoundException{
> if(connectionPool==null){
> connectionPool= new BoneCP(ConfigFactory.getBoneCpConfig());
> }
> return connectionPool.getConnection();
> }
> ConfigFactory.getBoneCpConfig():
> /**

> * 锟斤拷取bonecp锟斤拷锟斤拷锟斤拷息

Reply all
Reply to author
Forward
0 new messages