有沒(méi)有好心的大神告訴我一下,這是什么原因
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.
Exception in thread "main" java.sql.SQLException: 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 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
?? ?at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
?? ?at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
?? ?at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
?? ?at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
?? ?at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
?? ?at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
?? ?at java.sql.DriverManager.getConnection(Unknown Source)
?? ?at java.sql.DriverManager.getConnection(Unknown Source)
?? ?at com.imooc.DB.DBUtil.main(DBUtil.java:20)
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)
?? ?at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
?? ?at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
?? ?at java.lang.reflect.Constructor.newInstance(Unknown Source)
?? ?at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
?? ?at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
?? ?at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
?? ?at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2234)
?? ?at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2258)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
?? ?... 6 more
2022-03-25
$val是一個(gè)array其中包含很多項(xiàng)贊!就喜歡你這樣的!
2018-11-27
是時(shí)區(qū)錯(cuò)了原來(lái)。。已解決
2018-11-27
改了一下,現(xiàn)在變成這樣了
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.
Exception in thread "main" java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
?? ?at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
?? ?at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
?? ?at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
?? ?at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
?? ?at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
?? ?at java.sql.DriverManager.getConnection(Unknown Source)
?? ?at java.sql.DriverManager.getConnection(Unknown Source)
?? ?at com.imooc.DB.DBUtil.main(DBUtil.java:20)
2018-11-27
package com.imooc.DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBUtil {
?? ?private static final String URL="jdbc:mysql://127.0.0.1:3306/imooc";
?? ?private static final String USER="root";
?? ?private static final String PASSWORD="root";
?? ?
?? ?
?? ?
?? ?public static void main(String[] args) throws Exception{
??????? //加載驅(qū)動(dòng)程序
?? ??? ?Class.forName("com.mysql.jdbc.Driver");
?? ??? ?//獲得數(shù)據(jù)庫(kù)連接
?? ??? ?Connection conn=DriverManager.getConnection(URL, USER, PASSWORD);
?? ??? ?//操縱數(shù)據(jù)庫(kù)的連接操作數(shù)據(jù)庫(kù),實(shí)現(xiàn)增刪改查
?? ??? ?Statement stmt=conn.createStatement();
?? ?ResultSet rs=stmt.executeQuery("select user_name,age from imooc_goddess");
?? ?
?? ?while(rs.next()) {
?? ??? ?System.out.println(rs.getString("user_name")+","+rs.getInt("age"));
?? ??? ?
?? ??? ?
?? ?}
?? ?}
}
2018-11-26
你是怎么加載驅(qū)動(dòng)的,還有你的連接怎么寫的,發(fā)下代碼