美文网首页
jdbc的连接设置问题

jdbc的连接设置问题

作者: Bowiee | 来源:发表于2019-07-15 14:23 被阅读0次
    mysql版本:community-5.7.17.0
    

    在连接时,需要书写的:

    driverClassName=com.mysql.jdbc.Driver
    url=jdbc:mysql://localhost:3306/web01?useUnicode=true&characterEncoding=UTF-8&useSSL=true
    username=root
    password=root
    

    上面的useUnicode=true&characterEncoding=UTF-8都是用来完成编码的设置,而useSSL=true建立SSLl连接。如果未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求建立SSL连接。 若未设置,则会出现下列警告:

    WARN: Establishing SSL connection without server’s identity verification is not recommended. 
    According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. 
    For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. 
    You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
    

    在jdbc的配置中如果myaql是6.0及以上的,会有所不同,需要按照以下设置驱动:

    driverClassName=com.mysql.cj.jdbc.Driver
    

    否则就会报错:

    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 SPI and manual loading of the driver class is generally unnecessary.
    

    同时mysql 6.0以上还需要设置时区:

    url=jdbc:mysql://<u>localhost</u>:3306/ssm_spring?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=UTC
    

    不过值得注意的是UTC代表的是全球标准时间,我们使用的是北京时区,领先UTC八个小时。所以我们可以将时区设置为:

    serverTimezone=Asia/Shanghai
    

    相关文章

      网友评论

          本文标题:jdbc的连接设置问题

          本文链接:https://www.haomeiwen.com/subject/rwdnkctx.html