package com
.fy
;
import java
.sql
.Connection
;
import java
.sql
.DriverManager
;
import java
.sql
.Statement
;
public class Test2 {
public static void main(String
[] args
) throws Exception
{
delete(1);
}
private static void delete(int id
) throws Exception
{
Class
.forName("com.mysql.jdbc.Driver");
Connection conn
= DriverManager
.getConnection("jdbc:mysql://localhost:3306/day0901", "root", "1234");
String sql
= "delete from tb1 where id = " + id
;
Statement s
= conn
.createStatement();
int row
= s
.executeUpdate(sql
);
if(row
!= 0){
System
.out
.println("删除成功");
}else{
System
.out
.println("删除失败");
}
conn
.close();
s
.close();
}
}
数据库中表格原始数据
执行代码
数据库中表格删除后数据
再次执行代码,删除失败
转载请注明原文地址:https://tech.qufami.com/read-946.html