gpt4 book ai didi

java - while(rs1.next()) 不返回任何值

转载 作者:行者123 更新时间:2023-11-29 23:57:43 24 4
gpt4 key购买 nike

public void addPhoneInvoice(String IMEI,String price,String name, 
String pNumber) throws SQLException {

con = GetConnection.GetConnection();
stmt = con.createStatement();

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
String date1 = dateFormat.format(date);

this.price = Double.parseDouble(price);


String updatePhn = "DELETE FROM phonestock where IMEI = '"+IMEI+"'";
int j = stmt.executeUpdate(updatePhn);
if(j!=0){

String getDescriptionQuary = "SELECT PhoneName,WarrantyPeriod,YearORMonth FROM phonestock WHERE IMEI = '"+IMEI+"'";
ResultSet rs1 = stmt.executeQuery(getDescriptionQuary);

while(rs1.next()){
this.phoneName = rs1.getString("PhoneName");
this.warranty = rs1.getInt("WarrantyPeriod");
this.yearOrMonth = rs1.getString("YearORMonth");
}

String addPhnTemp = "INSERT INTO invoiceTemp(Description,Date,IMEI,Price,Amount,ContactName,ContactNumber,Warranty,YearOrMonth) VALUES ('"+phoneName+"','"+date1+"','"+IMEI+"',"+price+","+price+",'"+name+"','"+pNumber+"',"+warranty+",'"+yearOrMonth+"')";
String addPhnPer = "INSERT INTO invoicepermanent(Description,Date,IMEI,Price,Amount,ContactName,ContactNumber,Warranty,YearOrMonth) VALUES ('"+phoneName+"','"+date1+"','"+IMEI+"',"+price+","+price+",'"+name+"','"+pNumber+"',"+warranty+",'"+yearOrMonth+"')";

int i = stmt.executeUpdate(addPhnTemp);
i = stmt.executeUpdate(addPhnPer);

if(i != 0)
JOptionPane.showMessageDialog(null,"Success");
}
else
JOptionPane.showMessageDialog(null,"Error");
}

}

这显示成功,但 phoneNamewarrantyyearOrMonth 未从数据库返回。

最佳答案

因为executeUpdate 返回受影响的行数。如果它大于 0,则没有删除任何内容,并且您正在检查相同的 IMEI,但该 IMEI 已消失。因此,如果你说`System.err.println(rs1.isLast());它将返回 true,因为您的 select 语句没有找到任何行。

关于java - while(rs1.next()) 不返回任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25231401/

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