我不明白为什么这不起作用,我一直得到这个java.sql.SQLException:在开始结果集错误之前,我看了网上但是因为我一直盯着电脑屏幕好几个小时我的脑子都在疲惫不堪所以我找不到任何解决方案。请你能帮帮我吗?!谢谢
String from = "";
String subject= "";
String to= "";
String message= "";
try
{
while(retrieveMessages().next())
{
to = retrieveMessages().getString("tblEmail.to");
from = retrieveMessages().getString("tblEmail.from");
subject = retrieveMessages().getString("tblEmail.subject");
message = retrieveMessages().getString("tblEmail.message");
MailBox.add(new Email(to, from, subject, message));
}
}
catch (SQLException e)
{
e.printStackTrace();
}
答案 0 :(得分:1)
您多次致电retrieveMessages()
。你没有向我们展示它的作用并没有帮助,但我怀疑你想把它称为一次并将结果存储在一个局部变量中。目前,我怀疑您在一个结果集上调用next()
,然后在不同的结果集上调用getString()
。例如:
try (ResultSet results = retrieveMessages()) {
while (results.next()) {
String to = results.getString("tblEmail.to");
String from = results.getString("tblEmail.from");
String subject = results.getString("tblEmail.subject");
String message = results.getString("tblEmail.message");
MailBox.add(new Email(to, from, subject, message));
}
}