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

Posted 爱来无忧

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 连接mariadb 无法获取数据源的问题,在ubuntu上部署的时候(原创)相关的知识,希望对你有一定的参考价值。

问题:

连接数据库时报错:


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上部署的时候(原创)的主要内容,如果未能解决你的问题,请参考以下文章

MariaDB 使用错误的主机,无法连接 php 应用程序

kali 2020.4 在安装typecho时,无法连接数据库的问题

如何检测连接的数据库是 MariaDB 还是 MySQL?

SqlAlchemy 的 MySQL (mariaDB) 连接错误

java.sql.SQLException:无法从底层数据库获取连接! — HSQLDB

pyspark 与 MariaDB 的连接失败并出现 ClassNotFoundException