Spring_MySQL5.5_jdbc-8.0.11使用注意問題

先貼上在網上查到的最多的配置方式:

jdbc.username = root
jdbc.password = root
jdbc.driverClassName = com.org.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/mybookstore
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
   <property name="dataSource" ref="dataSource"></property>
</bean>

問題1:

新的配置driverClassName已經更改爲:

com.mysql.cj.jdbc.Driver

 問題2:

在修改driverClassName後運行仍然會報錯:

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)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

從錯誤提示中可以看到,問題在於"time zone”。這是因爲新的mysql驅動需要添加時區。

解決方法:只需要在jdbc.url = jdbc:mysql://localhost:3306/mybookstore後面加上?serverTimezone=UTC。

其他的參數有characterEncoding=utf8避免亂碼useSSL=true避免useSSL警告

最後一個問題:

在向項目中添加mysql-connector-java-8.0.11.jar的時候,記得不要通過複製粘貼到lib目錄下。在project Structure中進行添加。(感激自己直接複製粘貼好蠢。一直找不到jar包。)

project Structure

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章