Java实现CURD操作,最基础的版本
import org.junit.Test;
import java.sql.*;
public class JDBCDemo01 {
public static void main(String[] args) {
// testSelect();
// testInsert();
// testUpdate();
testDelete();
}
//删除
public static void testDelete(){
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/db1?useSSL=false&serverTimezone=UTC";
connection = DriverManager.getConnection(url, "root", "123456");
String sql = "delete from orderlist where id=9";
statement = connection.createStatement();
int row = statement.executeUpdate(sql); //进行添加行数,返回影响行数
System.out.println(row);
} catch (ClassNotFoundException e) {
e.printStackTrace();