码迷,mamicode.com
首页 > 数据库 > 详细

java 连接mariadb 无法获取数据源的问题,在ubuntu上部署的时候(原创)

时间:2017-09-16 20:46:50      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:checkout   log4   cli   please   span   mil   processor   append   nec   

问题:

连接数据库时报错:


log4j:WARN No appenders could be found for logger (com.mchange.v2.log.MLog).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.lang.RuntimeException: 无法从数据源获取连接
    at com.eteda.DbConnectionPool.EtedaDbPool.getConnection(EtedaDbPool.java:106)
    at com.zdc.MyServer.ZhangWork.UserLogin(ZhangWork.java:3567)
    at com.zdc.MyServer.ZhangWork.process(ZhangWork.java:96)
    at com.lyw.MyServer.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:50)
    at com.lyw.MyServer.catalina.connector.http.Hander.run(Hander.java:14)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
    at com.eteda.DbConnectionPool.EtedaDbPool.getConnection(EtedaDbPool.java:104)
    ... 7 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1469)
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
    ... 9 more


分析:

  问题原因在配置文件或者创建jdbc时连接数据库的问题上:

技术分享

先是执行这句:grant all on lx.* to "zhangdc"@‘%‘;
然后配置上面的文件,就可以了。

 下面是自己写的一个测试程序,也能通:

技术分享

 总结:从mysql数据库,换成mariadb后,先是将mysql的jar包换成mariadb-java-client-1.6.4.jar(最后问题解决了,回来测了一下,跟这个没关系)。然后进入数据库执行:

grant all on lx.* to "zhangdc"@‘%‘;后,用zhangdc用户登陆,问题就解决了。




有用提示:
grant all on db_name.* to ‘vincent’@‘%‘;


或者GRANT ALL PRIVILEGES ON db_base.* TO db_user @‘%‘ IDENTIFIED BY ‘db_passwd‘;

 

java 连接mariadb 无法获取数据源的问题,在ubuntu上部署的时候(原创)

标签:checkout   log4   cli   please   span   mil   processor   append   nec   

原文地址:http://www.cnblogs.com/zhangdaicong/p/7532164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!