刪除表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/秒
兩種方式計算)