1.没有导入架包
首先要导入mysql-connector-java这个架包到对应的文件目录下面。
2.时区错误问题
Exception in thread “main” java.sql.SQLException: The server time zone value
解决方案:在SQL命令后面的数据库名字后面加入
?serverTimezone=UTC
3.Exception in thread “main” java.sql.SQLException: SQL String cannot be empty
错误提示的意思是SQL字符串不能为空,通过检查发现,在进行预编译的时候,将SQL语句赋值为空了:
解决方案就是直接加个空格就行
PreparedStatement ps = con.prepareStatement(" ");
4.数据库名和数据库表名搞混。
String url = "jdbc:mysql://localhost:3306/bjpowernode?serverTimezone=UTC";
bjpowernode是需要操作的数据库表对应的数据库。