刪除操做的代碼實現sql
@Test /** * 刪除操做 */ public void demo3(){ Connection conn = null; PreparedStatement pstmt = null; try{ // 得到鏈接: conn = JDBCUtils.getConnection(); // 編寫SQL語句: String sql = "delete from user where id = ?"; // 預編譯SQL pstmt = conn.prepareStatement(sql); // 設置參數: pstmt.setInt(1, 4); // 執行SQL: int num = pstmt.executeUpdate(); if(num > 0){ System.out.println("刪除成功!"); } }catch(Exception e){ e.printStackTrace(); }finally{ JDBCUtils.release(pstmt, conn); } }