package cn;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class mails {
/**
* @param args
*/
public List<Mail> getSelect(String recive){
List<Mail> list=new ArrayList<Mail>();
Connection con=null;
PreparedStatement st=null;
ResultSet rst=null;
try{
con=aaq.getCon();
String sql="select*from mail where recive=?";
st=con.prepareStatement(sql);
st.setString(1, recive);
rst=st.executeQuery();
while(rst.next()){
Mail xf=new Mail();
xf.setIds(rst.getInt("ids"));
xf.setSender(rst.getString("sender"));
xf.setTitle(rst.getString("title"));
xf.setContent(rst.getString("content"));
xf.setRecive(rst.getString("recive"));
xf.setDate(rst.getString("date"));
xf.setState(rst.getInt("state"));
list.add(xf);
}
return list;
}catch(Exception e){
throw new RuntimeException(e);
}
finally{
aaq.closeAll(rst, st, con);
}
}
//���
public boolean insert(Mail mail){
Connection con=null;
Statement st=null;
ResultSet rst=null;
try{
con=aaq.getCon();
st=con.createStatement();
int row=st.executeUpdate("insert into mail values('"+mail.getIds()+"','"+mail.getSender()+"','"+mail.getTitle()+"','"+mail.getContent()+"','"+mail.getRecive()+"','"+mail.getDate()+"','"+mail.getState()+"'"+")");
if(row==1){
return true;
}
}catch(Exception e){
throw new RuntimeException(e);
}
finally{
aaq.closeAll(rst, st, con);
}
return false;
}
public Mail getSelects(int ids){
Connection con=null;
PreparedStatement st=null;
ResultSet rst=null;
try{
con=aaq.getCon();
String sql="select*from mail where ids=? ";
st=con.prepareStatement(sql);
st.setInt(1, ids);
rst=st.executeQuery();
while(rst.next()){
Mail xf=new Mail();
xf.setIds(rst.getInt("ids"));
xf.setSender(rst.getString("sender"));
xf.setTitle(rst.getString("title"));
xf.setContent(rst.getString("content"));
xf.setRecive(rst.getString("recive"));
xf.setDate(rst.getString("date"));
f.setState(rst.getInt("state"));
return xf;
}
}catch(Exception e){
throw new RuntimeException(e);
}
finally{
aaq.closeAll(rst, st, con);
}
return null;
}
public boolean getChange(int ids){
Connection con=null;
PreparedStatement st=null;
ResultSet rst=null;
try{
con=aaq.getCon();
String sql="update mail set state=1 where ids=?";
st=con.prepareStatement(sql);
st.setInt(1, ids);
int row =st.executeUpdate();
if(row==1){
return true;
}
}catch(Exception e){
throw new RuntimeException(e);
}
finally{
aaq.closeAll(rst, st, con);
}
return false;
}
public boolean getDelete(int ids){
Connection con=null;
PreparedStatement st=null;
ResultSet rst=null;
try{
con=aaq.getCon();
String sql="delete from mail where ids=?";
st=con.prepareStatement(sql);
st.setInt(1, ids);
int row =st.executeUpdate();
if(row==1){
return true;
}
}catch(Exception e){
throw new RuntimeException(e);
}
finally{
aaq.closeAll(rst, st, con);
}
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<form action="" method="post">
收件人:<input type="text" name="rs"><br><br>
标题: <input type="text" name="title"><br><br>
内容: <input type="text" name="content"><br><br>
<input type="submit" value="发送" >
</form>
</body>
</html
![]()