/* hao
* 2018-3-24 11:12:42
* JDBC删除
*/
package com.delete.www;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import com.mysql.jdbc.Driver;
public class DemoDelete {
public static void main(String[] args) throws Exception {
//通过 java代码删除数据库里面的数据
//1.获取驱动导包
//2.加载驱动 抛出异常
Class.forName("com.mysql.jdbc.Driver");
//3.获取链接
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/qq2018");
//4.编写sql语句
String sql = "delete from user01 where id = 10001;";
//5.执行者
PreparedStatement pst = con.prepareStatement(sql);
//6.执行
int x = pst.executeUpdate();
System.out.println("受影响的行数为:"+x);//受影响行
if(x>0){
System.out.println("删除成功");
}else{
System.out.println("删除失败");
}
pst.close();
con.close();
}
}
一个人只有用心去看,才能看到真实。事情的真相只用眼睛是看不见的。