eclipse使用jdbc连接mysql出现“The server time zone value '�й���׼ʱ��' is unrecognized or represents more th”

mysql中建表:

create table t_user(

Id int primary key auto_increment,

Name varchar(40),

Password varchar(40),

Email varchar(60),

Birthday date

);

插入数据:

 Insert into t_user(name,password,email,birthday)

Values('tiger','123456','[email protected]','1994-12-01'),

('rabbit','123456','[email protected]','1997-06-11'),

('sheep','123456','[email protected]','1995-07-15');

eclipse中查表

package com.monkey1024.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBC_Test01 {
    public static void main(String[] args) throws Exception {
        // 注册驱动
        //Class.forName("com.mysql.jdbc.Driver");
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 获取连接Connection
        Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/monkey1024?serverTimezone=UTC", "root", "123456");
        System.out.println("mysql connection success!");
        //得到执行sql语句的对象Statement
        Statement stmt=conn.createStatement();
        //执行sql语句,并返回结果
        ResultSet rs=stmt.executeQuery("select id,name,password,email,birthday from t_user");
        //处理结果
        while(rs.next()) {
            System.out.println(rs.getObject("id"));
            System.out.println(rs.getObject("name"));
            System.out.println(rs.getObject("password"));
            System.out.println(rs.getObject("email"));
            System.out.println(rs.getObject("birthday"));
            System.out.println("-----------------");
        }
        //关闭Connection
        rs.close();
        stmt.close();
        conn.close();
    }
}
注意:1) Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/monkey1024?serverTimezone=UTC", "root", "123456")中不添加?serverTimezone=UTC会出现如题报错。

           2)executeQuery中的sql不加“;”

你可能感兴趣的:(数据库,java)