删除数据库中指定表的内容
新建项目直接开写import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Test3 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// 加载驱动
Class.forName("com.mysql.jdbc.Driver");
// 获得连接对象
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/dbhui", "root", "root123");
//获取执行者对象
Statement statement = connection.createStatement();
// 构建sql语句
String sql = "DELETE FROM testinno WHERE id=1";
// 执行sql语句
int i = statement.executeUpdate(sql);
// 提示结果
if (i > 0) {
System.out.println("删除成功");
} else {
System.out.println("删除失败");
}
// 释放资源
statement.close();
connection.close();
// 提示自己的内容
System.out.println("程序退出");
}
}