老师检查作业~!

来源:3-6 自由编程

BirdMan98

2020-02-06 18:46:24

@Test

//删除数据

public void delete() {

Connection connection = null;

Statement statement = null;

try {

Class.forName("com.mysql.jdbc.Driver");

connection = (Connection) DriverManager.getConnection("jdbc:mysql:///test"+"?useUnicode=true&characterEncoding=utf-8","root","root");

statement = (Statement) connection.createStatement();

String sql = "delete from goods where id = 5";

int i = statement.executeUpdate(sql);

if (i>0) {

System.out.println("sucess");

}

} catch (Exception e) {

e.printStackTrace();

} finally {

if (connection != null) {

try {

connection.close();

} catch (SQLException e1) {

e1.printStackTrace();

}

connection=null;

}

if (statement != null) {

try {

statement.close();

} catch (SQLException e1) {

e1.printStackTrace();

}

statement=null;

}

}

}

http://img.mukewang.com/climg/5e3bee6d0935cbd706600129.jpg

http://img.mukewang.com/climg/5e3bee7c093ea5af08070189.jpg

写回答

1回答

好帮手慕阿莹

2020-02-06

同学完成的不错哦,成功完成了作业要求,继续加油哦!!!

如果我的回答解决了你的疑问,请采纳,祝学习愉快。

0

0 学习 · 8016 问题

查看课程