(急)JAVA实现邮件群发的问题
下面的代码有问题,麻烦高手指点下
“//从数据库中读出公司
NewStuInput cop = new NewStuInput();”这里在下面代码的运行时出现问题,麻烦指点
package cm;
import java.util.*;
import java.sql.Date;
import java.io.PrintStream;
import java.sql.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendMail {
DataBase dbconn;
ResultSet rs;
String strSQL;
String id, name, ok, late, early, ill,cop, busy, about, body;
//inputAndSendData
public void inputAndSendData(ArrayList inputDatet) {
String myMail, userName, passWord, host, copName, copMail, msg, temp;
PopupAuthenticator popAuthenticator = new PopupAuthenticator();
//得到发送邮件者所有信息
GetMail getMail = new GetMail();
myMail = getMail.getMyMail();
msg = ";
userName = getMail.getUserName();
passWord = getMail.getPassWord();
host = getMail.getHost();
//辅导员对学生本月的考勤和学习情况进行审核后,将其结果输入到数据库表stu_info中
inputData(inputDatet);
//从数据库中读出公司
NewStuInput cop = new NewStuInput();
ArrayList copList = cop.getCopList();
ArrayList stuList;
ArrayList oneStuInfo;
//按照公司读出学生学号并且按照学号读出该学生的信息
int numOfCop = copList.size();
for (int i = 0; i < numOfCop; i = i + 2) {
copName = (String) copList.get(i);
copMail = (String) copList.get(i + 1);
System.out.println("copName=" + copName);
System.out.println("copMail=" + copMail);
stuList = cop.getOneCop(copName);
try {
Properties props = new Properties();
Session sendMailSession;
Transport transport;
PasswordAuthentication pop =
popAuthenticator.performCheck(userName, passWord);
sendMailSession = Session.getInstance(props, popAuthenticator);
//邮件发送者信息
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(myMail));
//邮件接收地址
newMessage.setRecipient(
Message.RecipientType.TO,
new InternetAddress(copMail));
//邮件标
newMessage.setSubject("学生近来情况汇报");
msg = ";
//邮件内容,利用循环,按照学号来进行
for (int j = 0; j < stuList.size(); j++) {
msg = "尊敬的领导:您好!\n";
msg = msg + " 本月学生的概况汇报如下:\n";
id = (String) stuList.get(j);
oneStuInfo = cop.getOneStu(id);
msg = msg + (String) oneStuInfo.get(0) + ":";
msg = msg + "迟到" + (String) oneStuInfo.get(1) + "次,";
msg = msg + "早退" + (String) oneStuInfo.get(2) + "次,";
msg = msg + "病假" + (String) oneStuInfo.get(3) + "次,";
msg = msg + "事假" + (String) oneStuInfo.get(4) + "次,";
msg = msg + "身体状况" + (String) oneStuInfo.get(5) + ", ";
temp = (String) oneStuInfo.get(6);
System.out.println("教师评语为:" + temp);
if (temp.equals("待评"))
temp = "表现良好";
msg = msg + "教师评语为:" + temp + " \n";
}
//System.out.println(msg);
msg = msg + " 谢谢,如需要进一步资料可以回信或请致电垂询。\n";
if (!(msg.equals(" 谢谢,如需要进一步资料可以回信或请致电垂询。\n"))) {
msg = msg + " 中国民航飞行学院学生处上\n";
newMessage.setText(msg);
//权限验证
transport = sendMailSession.getTransport("smtp");
transport.connect(host, userName, passWord);
//发送邮件
transport.send(newMessage);
transport.close();
}
} catch (MessagingException m) {
System.out.println(m.toString());
}
}
setIsOKTo1();
}
//setIsOKTo1 将isOK设置为1,数据已经发出,故置为无效
public void setIsOKTo1(){
DataBase dbconn;
dbconn = new DataBase();
strSQL ="update stu_info set isOK = '1' where isOK = '0'";
dbconn.executeUpdate(strSQL);
}
//inputData首先将信息一条一条读出来,将其更新输入到数据库表stu_info中,但isOK仍然为0
public void inputData(ArrayList inputDatet) {
//strSQL="insert into stu_info(stu_id,stu_name,late,early,ill,busy,about,body,isOK) values (' ";
DataBase dbconn;
dbconn = new DataBase();
int n = inputDatet.size();
for (int i = 0; i < n; i = i + 8) {
id = (String) inputDatet.get(i);
name = (String) inputDatet.get(i + 1);
late = (String) inputDatet.get(i + 2);
early = (String) inputDatet.get(i + 3);
ill = (String) inputDatet.get(i + 4);
busy = (String) inputDatet.get(i + 5);
body = (String) inputDatet.get(i + 6);
about = (String) inputDatet.get(i + 7);
strSQL =
"update stu_info set stu_name='"
+ name
+ "',late='"
+ late
+ "',early='"
+ early
+ "',ill='"
+ ill
+ "',busy='"
+ busy
+ "',about='"
+ about
+ "',body='"
+ body
+ "' ,stu_id='"
+ id
+ "',isOK='0' "
+ "where stu_id='"
+ id
+ "' and isOK='0'";
//System.out.println(strSQL);
dbconn.executeUpdate(strSQL);
}
}
//fixData修改特别需要修改的学生信息(废除)
/*public void fixData(ArrayList inputDatet) {
DataBase dbconn;
dbconn = new DataBase();
int i = 0;
id = (String) inputDatet.get(i);
name = (String) inputDatet.get(i + 1);
late = (String) inputDatet.get(i + 2);
early = (String) inputDatet.get(i + 3);
ill = (String) inputDatet.get(i + 4);
busy = (String) inputDatet.get(i + 5);
body = (String) inputDatet.get(i + 6);
about = (String) inputDatet.get(i + 7);
strSQL =
"update stu_info set stu_name='"
+ name
+ "',late='"
+ late
+ "',early='"
+ early
+ "',ill='"
+ ill
+ "',busy='"
+ busy
+ "',about='"
+ about
+ "',body='"
+ body
+ "' ,stu_id='"
+ id
+ "',isOK='0' "
+ "where stu_id='"
+ id
+ "' and isOK='0'";
System.out.println(strSQL);
dbconn.executeUpdate(strSQL);
}*/
}

