四、删除
public class class4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
//1.链接数据库
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://192.168.8.60;DataBaseName=School","sa","123456");
//3.使用SQL语句对数据库进行操作
Statement stm = conn.createStatement();
//2.删除数据库SQL语句
String str = " delete from [Student] where [age] = '5' ";
//4.运行
stm.executeUpdate(str);
//5.判断是否删除了
if (stm.executeUpdate(str)==0){
System.out.println("数据删除");
}else{
System.out.println("数据没删除");
}