jsp9
2021-01-19 01:40
阅读:773
YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
标签:message change boolean tail hang inf main cal equals
$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;
}
}


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;
}
}
}


package com.gd.entity;
import java.util.Date;
public class Msg {
int msgid;
String usernname;
String title;
String msgcontent;
int state;
String sendto;
Date msg_create_date;
public int getMsgid() {
return msgid;
}
public void setMsgid(int msgid) {
this.msgid = msgid;
}
public String getUsernname() {
return usernname;
}
public void setUsernname(String usernname) {
this.usernname = usernname;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getMsgcontent() {
return msgcontent;
}
public void setMsgcontent(String msgcontent) {
this.msgcontent = msgcontent;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public String getSendto() {
return sendto;
}
public void setSendto(String sendto) {
this.sendto = sendto;
}
public Date getMsg_create_date() {
return msg_create_date;
}
public void setMsg_create_date(Date msg_create_date) {
this.msg_create_date = msg_create_date;
}
}


package com.gd.entity;
public class Users {
String username;
String password;
String email;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
jsp9
标签:message change boolean tail hang inf main cal equals
原文地址:https://www.cnblogs.com/akaxuan/p/13338628.html
评论
亲,登录后才可以留言!
