环境
JDK版本:jdk1.8.0_202
MySQL驱动版本:mysql-connector-java-8.0.22.jar
报错信息一
java.io.FileNotFoundException: D:\DevelopTools\Intellij%20Ideal\WorkSpace0\ClassesCode1\out\production\JDBC\jdbc.properties (系统找不到指定的路径。)
//获取src路径下的文件方式----------->ClassLoader 类加载器
ClassLoader classloader = JDBCUtils.class.getClassLoader();
URL res = classloader.getResource("jdbc.properties");
URI uri = res.toURI(); //在代码中加入此行代码,做出相应修改
String path = uri.getPath();
// System.out.println(path);
添加URI uri = res.toURI();
之后,会报红,那么就需要导包import java.net.URI;
,
接下来还会报错,就是toURI,还是报红,这个时候需要一个异常处理,在catch后面加上就可以
catch (URISyntaxException e) {
e.printStackTrace();
}
?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
报错信息二
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 specific time zone value if you want to utilize time zone support.
以上信息是提示时区处理的问题,那么在jdbc.properties
文件中,加上时区和编码方式即可,如下:
url = jdbc:mysql://localhost/dbTest?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
user = root
password = root
driver = com.mysql.cj.jdbc.Driver