gpt4 book ai didi

java - 撰写消息错误。 "Before start of ResultSet."

转载 作者:行者123 更新时间:2023-12-01 21:53:38 25 4
gpt4 key购买 nike

我正在尝试创建一个电子邮件管理系统。以下是撰写电子邮件的代码,但它抛出错误“在结果集启动之前”。你能帮我一下吗?

String To = to.getText();
String Cc = cc.getText();
String Bcc = bcc.getText();
String Sub = sub.getText();
String Msg = text.getText();
if(To.equals("") || Sub.equals("") || Msg.equals(""))
{
JOptionPane.showMessageDialog(null, "Please Fill All Appropiate Details");
}
else
{
try {

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/email management system","root", "ok" );
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select first,email,mail,name from login,curlogin;");
String from =rs.getString("mail");
String frmname =rs.getString("name");
String recipent = "";
String rname = "";
Boolean tof;
loop1: while(rs.next())
{
recipent = rs.getString("email");
rname = rs.getString("first");
if(recipent.equals(To))
{
tof = true;
break loop1;

}
else
{
tof= false;
}
}
if(tof=true)
{
stmt.executeUpdate("Insert into inbox Values('"+frmname+"','"+Sub+"','"+Msg+"',curDate(), curTime(),'"+rname+"','"+from+"');");
new inbox().setVisible(true);
this.dispose();
}
else
{
JOptionPane.showMessageDialog(null,"Sorry the 'To' Email you entered does not exist.");
}
ResultSet rs1 = stmt.executeQuery("select first,email,mail,name from login,curlogin;");
Boolean taf = false;
Boolean entered = false;
loop2: while(rs1.next())
{
recipent = rs1.getString("email");
rname = rs1.getString("first");
if(Cc.equals(""))
{

}
else
{
entered= true;
if(recipent.equals(Cc))
{
taf = true;
break loop2;

}
else
{
taf= false;
}
}
}
if(entered=true)
{
if(taf=true)
{
stmt.executeUpdate("Insert into inbox Values('"+frmname+"','"+Sub+"','"+Msg+"',curDate(), curTime(),'"+rname+"','"+from+"');");
new inbox().setVisible(true);
this.dispose();
}
else
{
JOptionPane.showMessageDialog(null,"Sorry the 'CC' Email you entered does not exist.");
}
}
ResultSet rs2 = stmt.executeQuery("select first,email,mail,name from login,curlogin;");
Boolean fot=false;
Boolean entered2 =false;
loop3: while(rs2.next())
{
recipent = rs2.getString("email");
rname = rs2.getString("first");
if(Bcc.equals(""))
{

}
else
{


if(recipent.equals(Bcc))
{
fot = true;
break loop3;

}
else
{
fot= false;
}
}
}
if(entered2=true)
{
if(fot=true)
{
stmt.executeUpdate("Insert into inbox Values('"+frmname+"','"+Sub+"','"+Msg+"',curDate(), curTime(),'"+rname+"','"+from+"');");
new inbox().setVisible(true);
this.dispose();
}
else
{
JOptionPane.showMessageDialog(null,"Sorry the 'CC' Email you entered does not exist.");
}

}

}

是否是因为创建了多个结果集?或者因为创建了多个 while 语句?

最佳答案

以下内容无效:

ResultSet rs = stmt.executeQuery("select first,email,mail,name from login,curlogin;");
String from =rs.getString("mail");
String frmname =rs.getString("name");

执行查询在位置 -1 处返回一个 ResultSet。您需要通过迭代器或首先调用 rs.next(); 来访问它(假设您有任何结果)。

关于java - 撰写消息错误。 "Before start of ResultSet.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34766760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com