CREATE DATABASE mydatabase; USE mydatabase; CREATE TABLE customers ( customerID varchar(8) primary key, name varchar(40) default NULL, phone varchar(16) default NULL ); INSERT INTO customers VALUES ('ADDIFK01','Frank Addinsell', '(718) 555-3911'); INSERT INTO customers VALUES ('ALBIBB01','Bob Albinoni', '(213) 555-7566');这段代码中package homework7_二_1_20221548; import java.sql.*; import javax.swing.JOptionPane; public class DemoDelete { public static void main(String args[]){ String url="jdbc:mysql://127.0.0.1:3306/student"; String user="root",pwd=""; Connection con; Statement sql; ResultSet rs; try{Class.forName("com.mysql.jdbc.Driver"); }catch (ClassNotFoundException e){ System.out.println("test"+e); } try { con = DriverManager.getConnection(url, user, pwd); sql = con.createStatement(); String mysql = "delete from customers where customerID='ADDIFK01' and 'ALBIBB01'"; System.out.println(mysql); int k = sql.executeUpdate(mysql); if (k == 1) JOptionPane.showMessageDialog(null, "删除记录成功", "成功", JOptionPane.PLAIN_MESSAGE); con.close(); }catch (SQLException ee){ JOptionPane.showMessageDialog(null,"删除记录失败"+ee,"失败",JOptionPane.ERROR_MESSAGE); } } }如何删除'ADDIFK01' 和 'ALBIBB01'对应的两条数据?
时间: 2024-02-14 08:10:57 浏览: 68
sql2008sql查询语句大全[借鉴].pdf
可以使用以下代码来删除'ADDIFK01'和'ALBIBB01'对应的两条数据:
```
String mysql = "delete from customers where customerID='ADDIFK01' or customerID='ALBIBB01'";
```
在这个代码中,使用了"or"语句来删除两条记录。如果使用"and"语句,则会删除没有对应的记录。
阅读全文