public class JdbcTest {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String url = "jdbc:mysql://localhost:3306/jdbc?serverTimezone=Asia/Shanghai" +
"&?useUnicode=true&characterEncoding=utf8&useSSL=false";
String username = "root";
String password = "1234";
// 1、加载驱动
Class.forName("com.mysql.jdbc.Driver");
// 2、连接数据库,代表数据库
Connection connection = DriverManager.getConnection(url, username, password);
// 3、向数据库发送sql的对象Statement PreparedStatement: CRUD
// 4、编写SQL
String sql = "delete from users where id=2"; //删除
PreparedStatement preparedStatement = connection.prepareStatement(sql);
// 执行删除操作 受影响的行数,数据库增删改都是用executeUpdate即可
int i = preparedStatement.executeUpdate();
System.out.println(i);
resultSet.close();
statement.close();
connection.close();
}
}
JDBC删除操作
最新推荐文章于 2024-06-21 14:47:54 发布