删除表students,再次查看数据库test中的表,并没有students。html
关闭链接,释放资源。java
executeBatch
)public class StudentDaoJDBCImpl implements StudentDao { @Override public int add(Student stu) { // TODO Auto-generated method stub Connection conn = null; PreparedStatement pstat = null; String sql = "insert into student(id,name) values(?,?) ";//表中有id和name这列 int result = -1; try { conn = JDBCUtil.getConnection(); pstat = conn.prepareStatement(sql); pstat.setInt(1, stu.getId()); pstat.setString(2, stu.getName()); result = pstat.executeUpdate(); }catch (SQLException sqle) { sqle.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ JDBCUtil.realeaseAll(null,pstat, conn); } return result; } @Override public int delete(int sid) { // TODO Auto-generated method stub Connection conn = null; PreparedStatement pstat = null; String sql = "delete from student where id=?";//表中有id和name这列 int result = -1; try { conn = JDBCUtil.getConnection(); pstat = conn.prepareStatement(sql); pstat.setInt(1, sid); result = pstat.executeUpdate(); }catch (SQLException sqle) { sqle.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ JDBCUtil.realeaseAll(null,pstat, conn); } return result; }
在程序中,当须要和数据进行交互的时候则使用这个接口,编写一个单独的类来实现它;在后期对程序的修改中,只需对DAO模式中的某个方法修改便可,不须要整个项目都进行修改mysql
条/秒
、KB/秒
两种方式计算)