📄 email.java
字号:
package xuesheng;
import conn.DataBaseConnection;
import java.sql.Date;
import java.sql.*;
import java.util.*;
import java.io.*;
public class Email
{
private Connection con=null;
public Email()
{
this.con=DataBaseConnection.getConnection();
}
//发送对象
public String getSender(String studentId)
{
Statement stmt = null;
ResultSet rst = null;
StringBuffer sBuf=new StringBuffer();
try {
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery("select studentId,stuName from xuesheng where stuclass in(select stuclass from xuesheng where studentId='"+studentId+"')");
while(rst.next()) {
String studentid= rst.getString("studentId").trim();
String stuName= rst.getString("stuName");
sBuf.append("<input type='checkbox' name='receiveStudentId' value='"+studentid+"'>"+stuName+"\n<br>");
}
}
catch (SQLException ex) {
return "";
}
finally
{
try{
if(stmt!=null){
stmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return sBuf.toString();
}
//删除
public void deleteEmail(String messageId)
{
PreparedStatement pstmt=null;
try
{
pstmt=con.prepareStatement("delete from email where messageId=?");
pstmt.setString(1,messageId);
pstmt.execute();
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}
//查询
public ResultSet executeQuery(String sql)
{
Statement stmt=null;
ResultSet rst=null;
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery(sql);
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rst;
}
public void executeUpdate(String sql)
{
Statement stmt=null;
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(sql);
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
}
//关闭
public void close()
{
try{
if(con!=null){
con.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
/*
public static void main(String[] args){
Email email=new Email();
String str=email.getSender("0368110051");
System.out.print(str);
} */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -