- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Statement;
- /*
- * 使用JDBC 完成sort表指定数据的删除
- *
- * 删除条件 分类id为s001
- */
- public class JDBCDeleteTest {
- public static void main(String[] args) throws Exception {
- //1. 注册驱动
- Class.forName("com.mysql.jdbc.Driver");
- //2. 获取连接
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/day22_JDBC", "root", "root");
- //3.创建执行者
- Statement stat = conn.createStatement();
- //4.执行sql结果
- String sql = "delete from sore where sid = 's001'";
- int line = stat.executeUpdate(sql);
- //5.处理结果集
- System.out.println("line"+line);
- //6.关闭资源
- stat.close();
- conn.close();
-
- }
- }
复制代码 |
|