JDBC
执行DML操作 executeUpdate()
删除、更新、添加
import java.io.PrintWriter;
import java.sql.*;
public class Main {
public static void main(String[] args) {
try (
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/study","root","123456");
Statement statement = connection.createStatement();
){
int i = statement.executeUpdate("insert into student values(4,'monkey','男')");
// statement.executeUpdate("delete from student where sid = 4");
// int i = statement.executeUpdate("update student set name = 'dog' where sid=3");
System.out.println("生效了:"+i+"行");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
