dbStatement = con.createStatement();
dbResult = dbStatement.executeQuery("SELECT Vendor_Code FROM temp ORDER BY status ASC ");
while (dbResult.next())
{
VendorCode=dbResult.getString("Vendor_Code");
System.out.println(VendorCode);
dbStatement.executeUpdate("INSERT INTO temp1 VALUES ('"+VendorCode+"')");
}
在上面的代码中,我按照状态的升序选择供应商代码列表,如果我不添加它可以正常工作:
dbStatement.executeUpdate("INSERT INTO temp1 VALUES ('"+VendorCode+"')");
进入while
循环。如果我添加这个,我得到的结果只是排序列表中的第一个值,并且它也被插入到 temp1 表中......
我在 NetBeans 中使用 Java swing 和 MySQL。知道为什么会这样吗?
如果我以其他方式执行上述代码,
dbStatement = con.createStatement();
dbInsert = con.createStatement();
dbResult = dbStatement.executeQuery("SELECT Vendor_Code FROM temp ORDER BY status ASC ");
while (dbResult.next())
{
VendorCode=dbResult.getString("Vendor_Code");
dbResult = dbInsert.executeQuery("SELECT Bid_No,Vendor_Name,Vendor_Address,Amount,Tax_Percentage,Amount_Aftertax,Expected_Deliverydate,Vendor_Code FROM purchase_bid where PE_Number='"+penumber+"' AND Vendor_Code='"+VendorCode+"' ");
while(dbResult.next())
{
Bid_Number=dbResult.getString("Bid_No");
vendor_name=dbResult.getString("Vendor_Name");
vendor_address=dbResult.getString("Vendor_Address");
Amount=dbResult.getString("Amount");
tax=dbResult.getString("Tax_Percentage");
date2=dbResult.getString("Expected_Deliverydate");
Amount_Aftertax=dbResult.getString("Amount_Aftertax");
venCode=dbResult.getString("Vendor_Code");
date3=date2.split("-");
String day="";
String month="";
String year="";
day=date3[2];
month=date3[1];
year=date3[0];
date=day+"-"+month+"-"+year;
addtoCart();//for displaying it in jTable
}
}
从purchase_bid 表中检索值不需要按升序排列VendorCode。然后它再次采用第一个排序值,jTable 中不显示任何内容。