public class JDBCDemo {
public static void main(String[] args) throws Exception {
// 注册驱动
Class.forName("com.mysql.jdbc.Driver");
// 获取链接
String url="jdbc:mysql://localhost:3306/qimeng?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false";
String username="root";
String password="123456";
Connection conn=DriverManager.getConnection(url,username,password);
// 定义sql
String sql="insert into qimeng_user (username,password) values('root','123456')";
// 获取执行sql的对象:Statement
Statement stmt=conn.createStatement();
// 执行sql
int count= (int) stmt.executeLargeUpdate(sql); //count:受影响行数的返回值
// 处理结果
System.out.println(count);
// 释放资源
stmt.close();
conn.close();
}
}
Exception in thread "main" java.sql.SQLException: Unknown system variable 'performance_schema'
一般来说数据库安装好后会有三张系统数据库,如图
很有可能是你讲这个performance_schema数据库给删了才导致的,或者说你的mysql驱动版本不一致导致的,如果你的mysql版本是8,一般驱动使用mysql-connector-java的8.0.11版本即可,链接驱动名是com.mysql.cj.jdbc.Driver,你上面的驱动名com.mysql.jdbc.Driver那么也就是说你使用的数据库是mysql5,对应的连接驱动引入的mysql-connector-java版本改为5.xx左右即可
下一个navicat
如果你的mysql是8.0版本及以上,将代码Class.forName("com.mysql.jdbc.Driver")改为Class.forName("com.mysql.cj.jdbc.Driver")试试,如果是8.0以上,看下pom文件中的连接驱动包和版本是否对应上;
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!