MySQLNonTransientConnectionException无法创建与数据库服务器的连接。引起:java.lang.NullPointerException

时间:2018-05-17 03:16:53

标签: java mysql jdbc spring-data-jpa

我在./mysql -u testuser -p的本地主机上运行了本地MySQL社区服务器(8.0.11)。

(我创建了一个数据库并为其注册了一个用户)。我可以使用以下终端查询来访问数据库:private final String URL= "jdbc:mysql://127.0.0.1:3306/db_example?useSSL=false"; private final String DB_USERNAME = "testuser"; private final String DB_PASSWORD = "pass"; public void connectAndInsertToDB() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception e) { System.out.println("JAVA: Class.forName() error"); e.printStackTrace(); } try { conn = DriverManager.getConnection(URL, DB_USERNAME, DB_PASSWORD); } catch (SQLException e) { System.out.println("Error in initializing a connection to MYSQL DB"); e.printStackTrace(); } }

我能够访问服务器。

我使用Spring和JDBC使用以下代码执行相同的操作:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
23:03:28,603 ERROR [stderr] (default task-3)    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
23:03:28,603 ERROR [stderr] (default task-3)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
23:03:28,604 ERROR [stderr] (default task-3)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
23:03:28,607 ERROR [stderr] (default task-3)    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
23:03:28,608 ERROR [stderr] (default task-3)    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
23:03:28,608 ERROR [stderr] (default task-3)    at com.mysql.jdbc.Util.getInstance(Util.java:387)
23:03:28,608 ERROR [stderr] (default task-3)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)
23:03:28,609 ERROR [stderr] (default task-3)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
23:03:28,609 ERROR [stderr] (default task-3)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
23:03:28,609 ERROR [stderr] (default task-3)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
23:03:28,610 ERROR [stderr] (default task-3)    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2332)
23:03:28,611 ERROR [stderr] (default task-3)    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
23:03:28,611 ERROR [stderr] (default task-3)    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
23:03:28,611 ERROR [stderr] (default task-3)    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
23:03:28,611 ERROR [stderr] (default task-3)    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
23:03:28,612 ERROR [stderr] (default task-3)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
23:03:28,612 ERROR [stderr] (default task-3)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
23:03:28,612 ERROR [stderr] (default task-3)    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
23:03:28,612 ERROR [stderr] (default task-3)    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
23:03:28,613 ERROR [stderr] (default task-3)    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
23:03:28,613 ERROR [stderr] (default task-3)    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
23:03:28,613 ERROR [stderr] (default task-3)    at java.sql.DriverManager.getConnection(DriverManager.java:664)
23:03:28,613 ERROR [stderr] (default task-3)    at java.sql.DriverManager.getConnection(DriverManager.java:247)
23:03:28,613 ERROR [stderr] (default task-3)    at com.voice4.spring.security.config.core.Inventory.connectAndInsertToDB(Inventory.java:41)
23:03:28,614 ERROR [stderr] (default task-3)    at com.voice4.spring.security.config.core.KomalController.indexPage(KomalController.java:36)
23:03:28,614 ERROR [stderr] (default task-3)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
23:03:28,614 ERROR [stderr] (default task-3)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
23:03:28,614 ERROR [stderr] (default task-3)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
23:03:28,614 ERROR [stderr] (default task-3)    at java.lang.reflect.Method.invoke(Method.java:497)
23:03:28,615 ERROR [stderr] (default task-3)    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
23:03:28,615 ERROR [stderr] (default task-3)    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
23:03:28,615 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
23:03:28,616 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
23:03:28,616 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
23:03:28,616 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
23:03:28,616 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
23:03:28,617 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
23:03:28,617 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
23:03:28,617 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
23:03:28,617 ERROR [stderr] (default task-3)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
23:03:28,618 ERROR [stderr] (default task-3)    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
23:03:28,618 ERROR [stderr] (default task-3)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
23:03:28,618 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
23:03:28,619 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
23:03:28,619 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
23:03:28,620 ERROR [stderr] (default task-3)    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
23:03:28,621 ERROR [stderr] (default task-3)    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
23:03:28,621 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,622 ERROR [stderr] (default task-3)    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
23:03:28,622 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,622 ERROR [stderr] (default task-3)    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
23:03:28,623 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,623 ERROR [stderr] (default task-3)    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
23:03:28,624 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,624 ERROR [stderr] (default task-3)    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
23:03:28,625 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,625 ERROR [stderr] (default task-3)    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
23:03:28,625 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,625 ERROR [stderr] (default task-3)    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
23:03:28,625 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,626 ERROR [stderr] (default task-3)    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:121)
23:03:28,626 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,626 ERROR [stderr] (default task-3)    at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100)
23:03:28,626 ERROR [stderr] (default task-3)    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
23:03:28,627 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,627 ERROR [stderr] (default task-3)    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)
23:03:28,627 ERROR [stderr] (default task-3)    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
23:03:28,627 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,627 ERROR [stderr] (default task-3)    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
23:03:28,627 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,628 ERROR [stderr] (default task-3)    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
23:03:28,628 ERROR [stderr] (default task-3)    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
23:03:28,628 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
23:03:28,628 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
23:03:28,628 ERROR [stderr] (default task-3)    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
23:03:28,629 ERROR [stderr] (default task-3)    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
23:03:28,629 ERROR [stderr] (default task-3)    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
23:03:28,629 ERROR [stderr] (default task-3)    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
23:03:28,629 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
23:03:28,629 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
23:03:28,630 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
23:03:28,630 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
23:03:28,630 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
23:03:28,630 ERROR [stderr] (default task-3)    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
23:03:28,630 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
23:03:28,631 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
23:03:28,631 ERROR [stderr] (default task-3)    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
23:03:28,631 ERROR [stderr] (default task-3)    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
23:03:28,631 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
23:03:28,632 ERROR [stderr] (default task-3)    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
23:03:28,632 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
23:03:28,633 ERROR [stderr] (default task-3)    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
23:03:28,633 ERROR [stderr] (default task-3)    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
23:03:28,633 ERROR [stderr] (default task-3)    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
23:03:28,634 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
23:03:28,634 ERROR [stderr] (default task-3)    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
23:03:28,634 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
23:03:28,634 ERROR [stderr] (default task-3)    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
23:03:28,635 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
23:03:28,635 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
23:03:28,636 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
23:03:28,636 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
23:03:28,636 ERROR [stderr] (default task-3)    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
23:03:28,636 ERROR [stderr] (default task-3)    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
23:03:28,637 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
23:03:28,637 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction$$Lambda$887/252834873.call(Unknown Source)
23:03:28,638 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
23:03:28,639 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$888/1261718761.call(Unknown Source)
23:03:28,639 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
23:03:28,639 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$888/1261718761.call(Unknown Source)
23:03:28,640 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
23:03:28,640 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$888/1261718761.call(Unknown Source)
23:03:28,640 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
23:03:28,641 ERROR [stderr] (default task-3)    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$888/1261718761.call(Unknown Source)
23:03:28,641 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
23:03:28,641 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
23:03:28,642 ERROR [stderr] (default task-3)    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
23:03:28,642 ERROR [stderr] (default task-3)    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
23:03:28,642 ERROR [stderr] (default task-3)    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
23:03:28,642 ERROR [stderr] (default task-3)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
23:03:28,643 ERROR [stderr] (default task-3)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
23:03:28,643 ERROR [stderr] (default task-3)    at java.lang.Thread.run(Thread.java:745)
23:03:28,644 ERROR [stderr] (default task-3) Caused by: java.lang.NullPointerException
23:03:28,644 ERROR [stderr] (default task-3)    at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3005)
23:03:28,644 ERROR [stderr] (default task-3)    at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1916)
23:03:28,644 ERROR [stderr] (default task-3)    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1845)
23:03:28,645 ERROR [stderr] (default task-3)    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)
23:03:28,645 ERROR [stderr] (default task-3)    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)
23:03:28,645 ERROR [stderr] (default task-3)    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)
23:03:28,645 ERROR [stderr] (default task-3)    ... 111 more

但后来我收到以下错误:

class MathSpec extends Specification {
    def "maximum of two numbers"() {
        expect:
            Math.max(a, b) == c

       where:
            a | b || c
            1 | 3 || 3
    }
}

在错误消息的底部,我得到一个提示,它是由空指针异常引起的,但我只是无法弄清楚我的查询/代码中什么可以为null?一切都与终端完美配合,而不是与JDBC。

6 个答案:

答案 0 :(得分:6)

您的程序中有哪个版本的mysql-connector-java? 我在我的电脑上运行你的代码,没有问题。但我将mysql-connector-java更改为版本5.1.26,我得到了同样的错误。您正在使用mysql 8.0.11,因此您可以尝试使用mysql-connector-java 8.0.11。

顺便说一句URL,你应该在版本8中这样写。

String URL= "jdbc:mysql://127.0.0.1:3306/db_example?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=GMT";

答案 1 :(得分:1)

不幸的是,如果您的设备使用的是旧版Android。 V6。上面的方法不起作用。 jdbc驱动程序V8 +与较早版本的Android不兼容。

答案 2 :(得分:0)

我遇到的问题是,我刚刚更新为mysql-connector-java-8.0.11的{​​{1}}。

已更改

mysql-connector-java-5.1.38

Class.forName("com.mysql.jdbc.Driver"); 

使用mysql-8.0.17.0

答案 3 :(得分:0)

就SpringBoot应用程序而言,如果您的项目包含多个模块,以使每个模块具有单独的pom.xml文件,请确保所有文件都具有与MySQL服务器兼容的相同版本的MySQL连接器。

答案 4 :(得分:0)

我尝试使用mysql-connector-java-8.0.11,但这并不能解决我的问题,下载了“ mysql-connector-java-8.0.11”后,解决了我的问题。项目所在的文件夹,然后我将整个文件夹(包括src文件夹)添加为外部库,并且由于某种原因解决了问题

答案 5 :(得分:0)

我更新了mysql版本,并且现在可以正常工作:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.22</version>
</dependency>