1.报错The server time zone value
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.
出现这种错误的原因是服务器的时区与本地不一致,因此需要单独设置一下时间,方法是在原有程序语句中加入 ?serverTimezone=UTC
具体代码如下:
修改之前:
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1", "root", "password");
修改之后:
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1?serverTimezone=UTC", "root", "password");
2.报错Unknow column ‘A’ in’where clause’
错误代码:
Exception in thread "main" java.sql.SQLSyntaxErrorException: Unknown column 'A' in 'where clause'
原因是如果sql中定义的类型是int型的可以不用加引号,但是如果是字符串类型的,必须加引号
修改之前:
String sql="update user set age=20 where name=A";
修改之后:
String sql="update user set age=20 where name='A'";
在设置name属性时,是varchar类型因此需要加引号