jsp10

2021-01-19 01:57

阅读:378

YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

标签:war   pre   extends   bsp   page   win   nbsp   ++   extend   

$Title$
用户名:
密码 :
验证码 :

   

注册新用户请单击此处
技术图片
技术图片




技术图片
技术图片






Title
欢迎登录 list = md.getMailByReceiver(u.getUsername()); %>
发件人 标题 收件人 状态 时间  
删除


发送信息请单击此处 退出登录请单击此处
技术图片
技术图片



Title

题目:

来自:

时间:

内容:

回复 返回
技术图片
技术图片



技术图片
技术图片


Title

题   目:

内   容:

         返回
技术图片
技术图片






技术图片
技术图片





技术图片
技术图片


Title

接收人:

题   目:

内   容:

         返回
技术图片
技术图片


Title
用户名:

密   码:

邮   箱:

   
技术图片
技术图片





Title
技术图片
技术图片


Title
技术图片
技术图片
package com.gd.dao;

import java.sql.*;

public class BaseDao {


    //获取连接
    public Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            // 2.建立连接
            conn = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/jdbc", "root", "1111");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }


    //关闭连接
    protected void closeAll(Connection con, PreparedStatement ps, ResultSet rs) {
        try {
            if (rs != null)
                rs.close();
            if (ps != null)
                ps.close();
            if (con != null)
                con.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
技术图片
技术图片
package com.gd.dao;

import com.gd.entity.Msg;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MsgDao extends BaseDao {
    Connection con = null;
    ResultSet rs = null;
    PreparedStatement ps = null;

    public List getMailByReceiver(String receiverName) {
        List list = new ArrayList();

        try {
            con = getConnection();
            String sql = "select * from msg where sendto=?";
            ps = con.prepareStatement(sql);
            ps.setString(1, receiverName);
            rs = ps.executeQuery();

            while (rs.next()) {
                Msg msg = new Msg();
                msg.setMsgid(rs.getInt("msgid"));
                msg.setMsgcontent(rs.getString("msgcontent"));
                msg.setMsg_create_date(rs.getDate("msg_create_date"));
                msg.setSendto(rs.getString("sendto"));
                msg.setState(rs.getInt("state"));
                msg.setTitle(rs.getString("title"));
                msg.setUsernname(rs.getString("username"));
                list.add(msg);
            }
            closeAll(con, ps, rs);

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return list;
    }

    public Msg getMailById(int id) {
        Msg msg = new Msg();
        try {
            con = getConnection();
            String sql = "select * from msg where msgid=?";
            ps = con.prepareStatement(sql);
            ps.setInt(1, id);
            rs = ps.executeQuery();
            while (rs.next()) {
                msg.setMsgid(rs.getInt("msgid"));
                msg.setMsgcontent(rs.getString("msgcontent"));
                msg.setMsg_create_date(rs.getDate("msg_create_date"));
                msg.setSendto(rs.getString("sendto"));
                msg.setState(rs.getInt("state"));
                msg.setTitle(rs.getString("title"));
                msg.setUsernname(rs.getString("username"));

            }
            closeAll(con, ps, rs);

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return msg;
    }

    public boolean delete(int id) {
        try {
            con = getConnection();
            String sql = "delete from msg where msgid=?";
            ps = con.prepareStatement(sql);
            ps.setInt(1, id);
            int row = ps.executeUpdate();
            if (row > 0) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeAll(con, ps, null);
        }
        return false;
    }

    public void altstate(int id) {
        try {
            con = getConnection();
            String sql = "update msg set state=0 where msgid=?";
            ps = con.prepareStatement(sql);
            ps.setInt(1, id);
            ps.executeUpdate();
            closeAll(con, ps, null);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }


}
技术图片
技术图片
package com.gd.dao;

import com.gd.entity.Users;

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

public class Register extends BaseDao {
    Connection con = null;
    ResultSet rs = null;
    PreparedStatement ps = null;

    public boolean register(Users users) {
        try {
            con = getConnection();
            String sql = "insert into users(username,PASSWORD,email) values (?,?,?)";
            ps = con.prepareStatement(sql);
            ps.setString(1, users.getUsername());
            ps.setString(2, users.getPassword());
            ps.setString(3, users.getEmail());

            int row = ps.executeUpdate();
            if (row > 0) {
                return true;
            } else {
                return false;
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeAll(con, ps, null);
        }


        return false;
    }
}
技术图片
技术图片
package com.gd.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ReplyDao extends BaseDao {
    Connection conn = null;
    PreparedStatement ps = null;

    public boolean insert(String username, String title, String msgcontent, String sendto, int state, Date msg_create_date) throws SQLException {

        conn = getConnection();
        String sql = "insert into msg(username,title,msgcontent,sendto,state,msg_create_date) values (?,?,?,?,?,?)";
        ps = conn.prepareStatement(sql);

        ps.setString(1, sendto);
        ps.setString(2, title);
        ps.setString(3, msgcontent);
        ps.setString(4, username);
        ps.setInt(5, state);
        ps.setDate(6, msg_create_date);
        int row = ps.executeUpdate();
        if (row > 0) {
            closeAll(conn, ps, null);
            return true;
        } else {
            closeAll(conn, ps, null);
            return false;
        }


    }

}
技术图片
技术图片
package com.gd.dao;

import java.sql.*;

public class SendMsessage extends BaseDao {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    public boolean checkinsert(String name) throws SQLException {
        conn = getConnection();
        String sql2 = "select * from users where username=?";
        ps = conn.prepareStatement(sql2);
        ps.setString(1, name);
        rs = ps.executeQuery();
        if (rs.next()) {
            closeAll(conn, ps, rs);
            return true;
        } else {
            closeAll(conn, ps, rs);
            return false;
        }
    }

    public boolean insert(String username, String title, String msgcontent, String sendto, int state, Date msg_create_date) throws SQLException {

        conn = getConnection();
        String sql = "insert into msg(username,title,msgcontent,sendto,state,msg_create_date) values (?,?,?,?,?,?)";
        ps = conn.prepareStatement(sql);

        ps.setString(1, username);
        ps.setString(2, title);
        ps.setString(3, msgcontent);
        ps.setString(4, sendto);
        ps.setInt(5, state);
        ps.setDate(6, msg_create_date);
        int row = ps.executeUpdate();
        if (row > 0) {
            closeAll(conn, ps, null);
            return true;
        } else {
            closeAll(conn, ps, null);
            return false;
        }


    }
}
技术图片
技术图片
package com.gd.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UsersDao extends BaseDao {
    public boolean login(String uname, String upwd) throws SQLException {
        Connection conn = getConnection();
        String sql = "select * from users where username=? and password=?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, uname);
        ps.setString(2, upwd);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            closeAll(conn, ps, rs);
            return true;
        } else {
            closeAll(conn, ps, rs);
            return false;

        }
    }

}

jsp10

标签:war   pre   extends   bsp   page   win   nbsp   ++   extend   

原文地址:https://www.cnblogs.com/akaxuan/p/13338629.html


评论


亲,登录后才可以留言!