package com.sql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Delete {
/**
* @param args
*/
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection ct;
try {
ct = DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","hequnjie");
Statement st=ct.createStatement();
/*按条件删除表格中的数据
* delete from student1 where id>=2;
* 删除表格中所有数据,保留表格结构
* delete from student1;
* 删除表格
* drop table student1;
* */
String sqlstr=" delete from student1 where id>=2;";
st.executeUpdate(sqlstr);
System.out.println("删除成功");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Delete {
/**
* @param args
*/
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection ct;
try {
ct = DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","hequnjie");
Statement st=ct.createStatement();
/*按条件删除表格中的数据
* delete from student1 where id>=2;
* 删除表格中所有数据,保留表格结构
* delete from student1;
* 删除表格
* drop table student1;
* */
String sqlstr=" delete from student1 where id>=2;";
st.executeUpdate(sqlstr);
System.out.println("删除成功");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}