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");
}
}
这显示了成功,但phoneName
,warranty
和yearOrMonth
没有从数据库返回。
答案 0 :(得分:0)
因为executeUpdate返回的行数受影响。如果它大于0,则不删除任何内容,并且您正在检查相同的IMEI,该IMEI已消失。因此,如果你说`System.err.println(rs1.isLast());它将返回true,因为select语句没有找到任何行。
答案 1 :(得分:0)
不要认为这些INSERT
个查询已成功执行。 Date
是Mysql的保留字。在它周围加上一些引用。