当前位置:Gxlcms > 数据库问题 > JDBC删除表数据

JDBC删除表数据

时间:2021-07-01 10:21:17 帮助过:5人阅读

package qddx.JDBC; 2 import java.sql.*; 3 public class DeletebbsVo { 4 public void deletebbsVo(int id){ 5 Connection conn = null; 6 PreparedStatement pst = null; 7 try{ 8 conn = JDBC_Connection.getConnection(); 9 String sql = "delete from article where id=?"; 10 pst=conn.prepareStatement(sql); 11 pst.setInt(1, id); 12 pst.executeUpdate(); 13 System.out.println("删除成功"); 14 }catch(SQLException e){ 15 e.printStackTrace(); 16 }finally{ 17 JDBC_Connection.free(null, conn, pst); 18 } 19 } 20 public static void main(String[] args) { 21 // TODO Auto-generated method stub 22 DeletebbsVo delete = new DeletebbsVo(); 23 int id = 3; 24 bbsVo vo = new bbsVo(); 25 QueryById queryById = new QueryById();//调用查询方法,查询id为3 的数据是否存在。 26 vo = queryById.QuerybbsVoById(id); 27 if(vo !=null){//查询不为空 则进行删除 28 delete.deletebbsVo(id); 29 }else{ 30 System.out.println("删除失败 id为"+id+"的数据不存在"); 31 32 } 33 34 } 35 36 }

 

JDBC删除表数据

标签:

人气教程排行