zoukankan      html  css  js  c++  java
  • mysql-connector-java 6版本的jdbc连接问题

    使用新版本6的jdbc驱动,会出现下面的问题

    Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_171]
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_171]
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_171]
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_171]
    

    就是未识别时区的问题,需要在jdbc连接的url上加上serverTimezone=UTC(世界标准时间)或者GMT(格林威治时间),写成

       private String url = "jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=UTC";
    
       private String username = "root";
    
       private String password = "root";
    
       private String driverClassName = "com.mysql.cj.jdbc.Driver";
    

    关于SSL连接的Warning
    SSL 是Secure Sockets Layer(安全套接层),可以在URL后面再添加一个属性useSSL=false就行了
    如果你不需要使用SSL连接,你需要通过设置useSSL=false来显式禁用SSL连接。
    如果你需要用SSL连接,就要为服务器证书验证提供信任库,并设置useSSL=true

     private String url = "jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=UTC&useSSL=false";
    
  • 相关阅读:
    WebService之CXF注解之三(Service接口实现类)
    WebService之CXF注解之二(Service接口)
    WebService之CXF注解之一(封装类)
    JavaScript实现获取table中某一列的值
    sprintf,snprintf的用法(可以作为linux中itoa函数的补充)
    linux下Epoll实现简单的C/S通信
    WebService之CXF注解报错(三)
    WebService之CXF注解报错(二)
    Flex文件读取报错
    WebService之CXF注解报错(一)
  • 原文地址:https://www.cnblogs.com/homeSicker/p/10233172.html
Copyright © 2011-2022 走看看