老师检查作业~!
来源: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;
}
}
}
1回答
同学完成的不错哦,成功完成了作业要求,继续加油哦!!!
如果我的回答解决了你的疑问,请采纳,祝学习愉快。