public static void main(String[] args) throws Exception {
//1、注册驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2、获取连接
String url = "jdbc:mysql://127.0.0.1:端口号/数据库名";
String username = "root";
String password = "root";
Connection connection = DriverManager.getConnection(url,username,password);
//3、定义sql语句
String sql = "update stu set gender='男' where name = '张三'";
//4、执行获取sql的对象
Statement statement = connection.createStatement();
//5、执行sql
int i = statement.executeUpdate(sql); //受影响的行数
//6、处理结果
//返回受影响的行
System.out.println(i);
//7、释放资源
statement.close();
connection.close();
}
恩,7个步骤写完了,可以开心的执行,等待结果了………………
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.M