⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picinfooperatebean.java

📁 一个图片管理程序
💻 JAVA
字号:
package com.sunnitech.bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;


public class PicInfoOperateBean {
    private picInfo _picinfo = new picInfo();

    public picInfo getpicInfo() {
        return this._picinfo;
    }

    public void setpicInfo(picInfo picinfo) {
        this._picinfo = picinfo;
    }

    public boolean selectPicInfo() {
        Connection conn = null;
        PreparedStatement prst = null;
        ResultSet rs = null;

        try {
            conn = DBConnection.getDBConnection();

            String sql = "select * from picinfo where UsrID=? and PicName=?";
            prst = conn.prepareStatement(sql);
            prst.setString(1, _picinfo.getUsrID());
            prst.setString(2, _picinfo.getPicName());
            rs = prst.executeQuery();

            while(rs.next()) {
                _picinfo.setPicID(rs.getLong(1));
                _picinfo.setUsrID(rs.getString(2));
                _picinfo.setPicName(rs.getString(3));
                _picinfo.setPicDescribe(rs.getString(4));
                _picinfo.setPicPath(rs.getString(5));
                _picinfo.setPicSize(rs.getString(6));
                _picinfo.setScreenType(rs.getInt(7));
            }
        } catch(Exception e) {
            System.out.println("pic select error: " + e.toString());

            return false;
        } finally {
            try {
                rs.close();
                prst.close();
                conn.close();
            } catch(Exception e) {
                System.out.println("pic select error0: " + e.toString());
            }
        }

        return true;
    }

    public boolean updatePicInfo() {
        Connection conn = null;
        PreparedStatement prst = null;

        try {
            conn = DBConnection.getDBConnection();

            String sql = "update picinfo set PicDescribe=?, PicPath=?, PicSize=?, ScreenType=? where UsrID=? and PicName=?";
            prst = conn.prepareStatement(sql);
            prst.setString(1, _picinfo.getPicDescribe());
            prst.setString(2, _picinfo.getPicPath());
            prst.setString(3, _picinfo.getPicSize());
            prst.setInt(4, _picinfo.getScreenType());
            prst.setString(5, _picinfo.getUsrID());
            prst.setString(6, _picinfo.getPicName());
            prst.executeUpdate();
        } catch(Exception e) {
            System.out.println("pic update error: " + e.toString());

            return false;
        } finally {
            try {
                prst.close();
                conn.close();
            } catch(Exception e) {
                System.out.println("pic update error0: " + e.toString());
            }
        }

        return true;
    }

    public boolean insertPicInfo() {
        Connection conn = null;
        PreparedStatement prst = null;

        try {
            conn = DBConnection.getDBConnection();

            String sql = "insert into picinfo values(?,?,?,?,?,?,?)";
            prst = conn.prepareStatement(sql);
            prst.setLong(1, _picinfo.getPicID());
            prst.setString(2, _picinfo.getUsrID());
            prst.setString(3, _picinfo.getPicName());
            prst.setString(4, _picinfo.getPicDescribe());
            prst.setString(5, _picinfo.getPicPath());
            prst.setString(6, _picinfo.getPicSize());
            prst.setInt(7, _picinfo.getScreenType());
            prst.executeUpdate();
        } catch(Exception e) {
            System.out.println("pic insert error: " + e.toString());

            return false;
        } finally {
            try {
                prst.close();
                conn.close();
            } catch(Exception e) {
                System.out.println("pic insert error0: " + e.toString());
            }
        }

        return true;
    }

    public boolean deletePicInfo() {
        Connection conn = null;
        PreparedStatement prst = null;

        try {
            conn = DBConnection.getDBConnection();

            String sql = "delete from picinfo where UsrID=? and PicName=?";
            prst = conn.prepareStatement(sql);
            prst.setString(1, _picinfo.getUsrID());
            prst.setString(2, _picinfo.getPicName());
            prst.executeUpdate();
        } catch(Exception e) {
            System.out.println("pic delete error: " + e.toString());

            return false;
        } finally {
            try {
                prst.close();
                conn.close();
            } catch(Exception e) {
                System.out.println("pic delete error0: " + e.toString());
            }
        }

        return true;
    }

    public Collection getPicInfoArray() {
        Connection conn = null;
        PreparedStatement pstm = null;
        ResultSet rs = null;
        Collection collection = new ArrayList();

        try {
            conn = DBConnection.getDBConnection();

            String str = "select count(*) from PicInfo where UsrID=?";
            pstm = conn.prepareStatement(str);
            pstm.setString(1, _picinfo.getUsrID());
            rs = pstm.executeQuery();

            int list_count = 0;

            if(rs.next()) {
                list_count = rs.getInt(1);
                rs.close();
                rs = null;
                pstm.close();
                pstm = null;
            }

            if(list_count > 0) {
                str = "select * from PicInfo where UsrID=? order by PicID";
                pstm = conn.prepareStatement(str);
                pstm.setString(1, _picinfo.getUsrID());
                rs = pstm.executeQuery();

                while(rs.next()) {
                    picInfo pic = new picInfo();
                    pic.setPicID(rs.getLong(1));
                    pic.setUsrID(rs.getString(2));
                    pic.setPicName(rs.getString(3));
                    pic.setPicDescribe(rs.getString(4));
                    pic.setPicPath(rs.getString(5));
                    pic.setPicSize(rs.getString(6));
                    collection.add(pic);
                }
            }
        } catch(Exception e) {
            System.out.println("get pic array error: " + e.toString());
        } finally {
            try {
                if(rs != null) {
                    rs.close();
                }

                if(pstm != null) {
                    pstm.close();
                }

                conn.close();
            } catch(Exception e) {
                System.out.println("get pic array error0: " + e.toString());
            }
        }

        return collection;
    }

    public boolean getMaxPicID() {
        Connection conn = null;
        PreparedStatement prst = null;
        ResultSet rs = null;

        try {
            conn = DBConnection.getDBConnection();

            String sql = "select max(PicID) from picinfo";
            prst = conn.prepareStatement(sql);
            rs = prst.executeQuery();

            if(rs.next()) {
                _picinfo.setPicID(rs.getLong(1) + 1L);
            } else {
                _picinfo.setPicID(1L);
            }
        } catch(Exception e) {
            System.out.println("get max PicID error: " + e.toString());

            return false;
        } finally {
            try {
                rs.close();
                prst.close();
                conn.close();
            } catch(Exception e) {
                System.out.println("get max PicID error0: " + e.toString());
            }
        }

        return true;
    }
}

⌨️ 快捷键说明

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