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

📄 lybean.java~29~

📁 基于b/s模式的jsp在线考试系统
💻 JAVA~29~
字号:
package com.gton.bean;

import java.sql.*;
import java.util.*;
import com.gton.util.DBUtil;

public class LyBean {
    private String ly_Author;
    private String ly_Content;
    private String ly_Date;
    private int ly_ID;
    public LyBean() {
    }

    public void setLy_Author(String ly_Author) {
        this.ly_Author = ly_Author;
    }

    public void setLy_Content(String ly_Content) {
        this.ly_Content = ly_Content;
    }

    public void setLy_Date(String ly_Date) {
        this.ly_Date = ly_Date;
    }

    public void setLy_ID(int ly_ID) {
        this.ly_ID = ly_ID;
    }

    public String getLy_Author() {
        return ly_Author;
    }

    public String getLy_Content() {
        return ly_Content;
    }

    public String getLy_Date() {
        return ly_Date;
    }

    public int getLy_ID() {
        return ly_ID;
    }

    public static boolean liuyan(String name, String content) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        int rowCount = 0;
        boolean flag = false;

        try {
            conn = DBUtil.getConnection();
            String sql = "insert into Ly(Ly_Author, Ly_Content) values(?,?)";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, name);
            pstmt.setString(2, content);
            rowCount = pstmt.executeUpdate();
            if (rowCount > 0) {
                flag = true;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtil.closeConnection(null, pstmt, conn);
        }
        return flag;
    }


    public static ArrayList queryAll() {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        LyBean bean = null;
        ArrayList list = null;

        try {
            conn = DBUtil.getConnection();
            String sql = "select * from Ly";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            list = new ArrayList();
            while (rs.next()) {
                bean = new LyBean();
                bean.setLy_ID(rs.getInt("Ly_ID"));
                bean.setLy_Author(rs.getString("Ly_Author"));
                bean.setLy_Content(rs.getString("Ly_Content"));
                bean.setLy_Date(rs.getString("Ly_Date"));
                list.add(bean);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtil.closeConnection(rs, pstmt, conn);
        }
        return list;
    }


    public static boolean delete(int Ly_Id) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        int rowCount = 0;
        boolean flag = false;
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            conn = DriverManager
                   .getConnection(
                           "jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=Kaoshi",
                           "sa", "");
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        try {
            String sql = "delete from Ly where Ly_ID=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, Ly_Id);
            rowCount = pstmt.executeUpdate();
            if (rowCount > 0) {
                flag = true;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (pstmt != null) {
                    pstmt.close();
                    pstmt = null;
                }
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return flag;
    }
}

⌨️ 快捷键说明

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