public class demo {
public static void main(String[] args) throws ClassNotFoundException {
Class.forName("com.mysql.jc.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/db1";
String username = "root";
String password = "1234";
Connection conn = DriverManger.getConnection(url,username,password);
String sql = "update emp1 set salary = 5000 where id = 1";
Statement stat = conn.createStatement();
int count = stat.excuteUpdate(sql);
System.out.println(count);
stat.close();
conn.close();
}
}
有具体运行截图吗?
注册驱动是
Class.forName("com.mysql.cj.jdbc.Driver");
你这个应该将根目录右键 Mark Directory As -> Source Root。
另外你注册驱动的类路径写错了,mysql-connect 8.0之前
应该是"com.mysql.jdbc.Driver",8.0及以后是"com.mysql.cj.jdbc.Driver"