jfinal c3p0配置参数问题

taotao00100 发布于 2015/08/24 12:16
阅读 1K+
收藏 0
@Override  
public void configPlugin(Plugins me) {  
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");   
Properties p = new Properties();   
try {   
p.load(inputStream);   
} catch (IOException e1) {   
e1.printStackTrace();   
}   
String url = p.getProperty("url");
String name = p.getProperty("name");
String password = p.getProperty("password");
C3p0Plugin  cp  =  new  C3p0Plugin(url, name, password);
//C3p0Plugin  cp  =  new  C3p0Plugin("jdbc:mysql://localhost/r1u75h7f919041bf?characterEncoding=utf8", "root", "admin");
me.add(cp);
ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
arp.addMapping("function", Function.class);
arp.addMapping("staff", Staff.class);
me.add(arp);

}  

使用配置文件读取加载c3p0出错

其中url和name和password是有值的

但使用被注释的那一句就没问题,为什么?

错误信息:

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1127)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1114)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1855)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)


八月 24, 2015 12:08:49 下午 com.mchange.v2.resourcepool.BasicResourcePool 
警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@c1e2720 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
八月 24, 2015 12:08:49 下午 com.mchange.v2.resourcepool.BasicResourcePool 
警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@64e6b46f -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1127)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1114)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1855)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)


八月 24, 2015 12:08:49 下午 com.mchange.v2.resourcepool.BasicResourcePool 
警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@c1e2720 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
八月 24, 2015 12:08:49 下午 com.jfinal.core.Config error
严重: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. 
java.sql.SQLException: Connections could not be acquired from the underlying database!

加载中
1
taotao00100
taotao00100
原来配置文件中的"和空格都会被读取到。。。。
0
金玉良妍
金玉良妍

me.setDrivername();

没记错要加这个.

taotao00100
taotao00100
me没有这个方法 c3p0有一个cp.setDriverClass("com.mysql.jdbc.Driver.") 但是还是没用。 主要的问题是c3p0通过参数的形式不行,直接写就可以
0
莫铭
莫铭

java.sql.SQLException: No suitable driver 没找到合适的驱动


(1)c3p0Plugin默认是mysql的驱动,又没报ClassNotFound,说明jar包已经包含,可能是默认值没生效,试试:

C3p0Plugin  cp  =  new  C3p0Plugin(url, name, password,“com.mysql.jdbc.Driver”);



taotao00100
taotao00100
C3p0Plugin cp = new C3p0Plugin(url, name, password,"com.mysql.jdbc.Driver"); 也不行
0
taotao00100
taotao00100
url="jdbc:mysql://localhost/r1u75h7f919041bf?characterEncoding=utf8" name="root" password="admin",这是配置文件的内容
0
taotao00100
taotao00100
if("jdbc:mysql://localhost/r1u75h7f919041bf?characterEncoding=utf8".equals(url)){ System.out.println("?????"); } if("root".equals(name)){ System.out.println("?2"); } if("admin".equals...
0
莫铭
莫铭
url="jdbc:mysql://localhost/r1u75h7f919041bf?characterEncoding=utf8" name="root" password="admin" 配置文件你加了引号""吗?配置文件是不用加引号的。直接 name=root这样就好。
返回顶部
顶部