关于mysql数据库连接问题

我把程序发布出去之后,启动服务tomcat报如下错,是怎么回事,怎么解决

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class
is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SP
I and manual loading of the driver class is generally unnecessary.
22:07:47.421 ERROR c.h.c.c.s.AbstractWebAppContextLoader   - Error initializing
application
java.lang.RuntimeException:
==============================================================================
ERROR: Cannot check and update database. See the stacktrace below for details.
==============================================================================
        at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.updateDatabaseOnSta
rt(DbUpdaterImpl.java:89) ~[cuba-core-7.0.10.jar:7.0.10]
        at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.applicationInitiali
zed(DbUpdaterImpl.java:79) ~[cuba-core-7.0.10.jar:7.0.10]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.
0_181]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.

把jdbc驱动改为com.mysql.cj.jdbc.Driver 又报如下错

2019-09-29 17:14:22.179 ERROR [main] com.haulmont.cuba.core.sys.AbstractWebAppContextLoader - Error initializing application
java.lang.RuntimeException: 
===================================================================
ERROR: Cannot check database. See the stacktrace below for details.
===================================================================
	at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.checkDatabaseOnStart(DbUpdaterImpl.java:117) ~[cuba-core-7.0.10.jar:7.0.10]
	at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.applicationInitialized(DbUpdaterImpl.java:81) ~[cuba-core-7.0.10.jar:7.0.10]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
	at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:261) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:179) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:142) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at com.haulmont.cuba.core.sys.EventsImpl.publish(EventsImpl.java:33) ~[cuba-global-7.0.10.jar:7.0.10]
	at com.haulmont.cuba.core.sys.AbstractAppContextLoader.initAppContext(AbstractAppContextLoader.java:66) ~[cuba-global-7.0.10.jar:7.0.10]
	at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:78) ~[cuba-global-7.0.10.jar:7.0.10]
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4663) [catalina.jar:9.0.14]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5131) [catalina.jar:9.0.14]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.14]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713) [catalina.jar:9.0.14]
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690) [catalina.jar:9.0.14]
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695) [catalina.jar:9.0.14]
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1133) [catalina.jar:9.0.14]
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1868) [catalina.jar:9.0.14]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_181]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_181]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-util.jar:9.0.14]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112) [na:1.8.0_181]
	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1045) [catalina.jar:9.0.14]
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:429) [catalina.jar:9.0.14]
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1577) [catalina.jar:9.0.14]
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309) [catalina.jar:9.0.14]
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123) [catalina.jar:9.0.14]
	at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424) [catalina.jar:9.0.14]
	at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:367) [catalina.jar:9.0.14]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:934) [catalina.jar:9.0.14]
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831) [catalina.jar:9.0.14]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.14]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382) [catalina.jar:9.0.14]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372) [catalina.jar:9.0.14]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_181]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-util.jar:9.0.14]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [na:1.8.0_181]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907) [catalina.jar:9.0.14]
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [catalina.jar:9.0.14]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.14]
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423) [catalina.jar:9.0.14]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.14]
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:933) [catalina.jar:9.0.14]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.14]
	at org.apache.catalina.startup.Catalina.start(Catalina.java:637) [catalina.jar:9.0.14]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350) [bootstrap.jar:9.0.14]
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492) [bootstrap.jar:9.0.14]
Caused by: com.haulmont.cuba.core.sys.DbInitializationException: Error connecting to database: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
	at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.dbInitialized(DbUpdaterEngine.java:177) ~[cuba-core-7.0.10.jar:7.0.10]
	at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.checkDatabaseOnStart(DbUpdaterImpl.java:98) ~[cuba-core-7.0.10.jar:7.0.10]
	... 57 common frames omitted
Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
	at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2385) ~[tomcat-dbcp.jar:9.0.14]
	at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2110) ~[tomcat-dbcp.jar:9.0.14]
	at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1563) ~[tomcat-dbcp.jar:9.0.14]
	at com.haulmont.cuba.core.sys.jdbc.ProxyDataSource.getConnection(ProxyDataSource.java:35) ~[cuba-core-7.0.10.jar:7.0.10]
	at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.dbInitialized(DbUpdaterEngine.java:158) ~[cuba-core-7.0.10.jar:7.0.10]
	... 58 common frames omitted
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.15.jar:8.0.15]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.15.jar:8.0.15]
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.15.jar:8.0.15]
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.15.jar:8.0.15]
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.15.jar:8.0.15]
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.15.jar:8.0.15]
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.15.jar:8.0.15]
	at org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:53) ~[tomcat-dbcp.jar:9.0.14]
	at org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:291) ~[tomcat-dbcp.jar:9.0.14]
	at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2395) ~[tomcat-dbcp.jar:9.0.14]
	at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2381) ~[tomcat-dbcp.jar:9.0.14]
	... 62 common frames omitted

看上去是 mysql 的权限配置问题,请用 mysql workbench 或者其他工具检查一下 root 用户登录的情况

太 谢 谢了!太 谢 谢了!

%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20190930152615
调试的时候老报这个错是怎么回事,配置的都正确,单独启动deploy中的服务没有问题:innocent:

1赞

已解决,https://doc.cuba-platform.cn/manual-7.1-chs/db_mysql_features.html,没安装mysql-connector-java.jar插件

1赞

因为 mysql 的 driver 不是free的,所以 CUBA 默认不提供。

换成新的驱动,那是不是mysql5.x也得换成新版的mysql8.x阿

不是说需要换驱动,而是 MySQL 驱动由于许可限制,Studio 不能分发。需要手动下载安装。具体可以看上面提到的链接: