JDBC之简单删除
public static void main(String[] args){
String sId = JOptionPane.showInputDialog("请输入id:");
int id = Integer.parseInt(sId);
Class.forName("com.mysql.jdbc.Driver");
Driver d = new Driver() //注意导包选择mysql
DriverManger.rigsterDrivaer(d);
Connection conn = DrigerManger.getConnection("jdbc:mysql://localhost:3306/servlet","root","root");
String sql = "delete from user1 where id=?"; //注意一定要带条件
PrepareStatement ps = conn.prepareStament(sql);
ps.setObject(1,id);
int result = ps.executeUpdate();
if(result > 0){
JOptionPane.showMessageDialog(null,"删除成功");
}else{
JOptionPane.showMessageDialog(null,"删除删除");
}
}