deletemodel.java

来自「新闻发布系统」· Java 代码 · 共 119 行

JAVA
119
字号
/*
 * DeleteModel.java
 *
 * Created on 2007年3月20日, 上午8:13
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package News.ProcessData;

import java.sql.*;

import News.Common.DBManager;
/**
 *
 * @author 吴西博
 */
public class DeleteModel {
    private Connection conn=null;
    private PreparedStatement ps=null;
    /** Creates a new instance of DeleteModel */
    public DeleteModel() {
    }
    
    public boolean DeleteLink(String IDparam)
    {
        int i=0,ID=0;
        try{
            ID=Integer.parseInt(IDparam);
        }catch(NumberFormatException e){ID=-1;}
        try{
        conn=DBManager.getConnection();
        ps=conn.prepareStatement("delete from Links where ID=?");
        ps.setInt(1,ID);
        i=ps.executeUpdate();
        }catch(SQLException e){System.out.println(e.getMessage());return false;}
        finally{
            try{
        if(ps!=null){ps.close();}
        if(conn!=null){conn.close();}
            }catch(SQLException e1){System.out.println(e1.getMessage());}
        }
        if(i>0)
            return true;
        else return false;
    }
    
    public boolean DeleteNotice(String IDparam)
    {
        int i=0,ID=0;
        try{
            ID=Integer.parseInt(IDparam);
        }catch(NumberFormatException e){ID=-1;}
        try{
        conn=DBManager.getConnection();
        ps=conn.prepareStatement("delete from Notice where ID=?");
        ps.setInt(1,ID);
        i=ps.executeUpdate();
        }catch(SQLException e){System.out.println(e.getMessage());return false;}
        finally{
            try{
        if(ps!=null){ps.close();}
        if(conn!=null){conn.close();}
            }catch(SQLException e1){System.out.println(e1.getMessage());}
        }
        if(i>0)
            return true;
        else return false;
    }
    
    public boolean DeleteCatalog(String IDparam)
    {
        int i=0,ID=0;
        try{
            ID=Integer.parseInt(IDparam);
        }catch(NumberFormatException e){ID=-1;}
        try{
        conn=DBManager.getConnection();
        ps=conn.prepareStatement("delete from Catalogs where ID=?");
        ps.setInt(1,ID);
        i=ps.executeUpdate();
        }catch(SQLException e){System.out.println(e.getMessage());return false;}
        finally{
            try{
        if(ps!=null){ps.close();}
        if(conn!=null){conn.close();}
            }catch(SQLException e1){System.out.println(e1.getMessage());}
        }
        if(i>0)
            return true;
        else return false;
    }
    
    public boolean DeleteNew(String IDparam)
    {
        int i=0,ID=0;
        try{
            ID=Integer.parseInt(IDparam);
        }catch(NumberFormatException e){ID=-1;}
        try{
        conn=DBManager.getConnection();
        ps=conn.prepareStatement("delete from News where ID=?");
        ps.setInt(1,ID);
        i=ps.executeUpdate();
        }catch(SQLException e){System.out.println(e.getMessage());return false;}
        finally{
            try{
        if(ps!=null){ps.close();}
        if(conn!=null){conn.close();}
            }catch(SQLException e1){System.out.println(e1.getMessage());}
        }
        if(i>0)
            return true;
        else return false;
    }
    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?