老师,我在写进货单的功能,目前不能实现多行添加,只能添加第二行的数据,请问我的方法有问题吗?
public static boolean insertRukuInfo(TbRukuMain ruMain) {
try {
boolean autoCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
java.sql.Date date = new java.sql.Date(jhsjDate.getTime());// 创建日期对象
String maxId = Dao.getKucunMaxId(date);// 获取最大的“进货票号”
insert("insert into tb_ruku_main values('" + ruMain.getRkId()
+ "','" + ruMain.getWlh() + "','" + ruMain.getHwname() + "','"
+ ruMain.getGg() + "','"
+ ruMain.getShelf() + "','"
+ ruMain.getHwwz() + "','" + ruMain.getHums() + "','"
+ ruMain.getRkdate() + "','"
+ ruMain.getJsr()
+ "')");
Set<TbRukuDetail> rkDetails = ruMain.getTabRukuDetails();
for (Iterator<TbRukuDetail> iter = rkDetails.iterator(); iter
.hasNext();) {
TbRukuDetail details = iter.next();
//添加入库详细表记录
insert("insert into tb_ruku_detail values('" + ruMain.getRkId() + "','"
+ details.getTabkucun()+ "','"
+ details.getSl() + "','" + details.getDw() + "')");
//添加或修改库存表记录
//item.setId(details.getTabSpinfo());
//TbSpinfo spInfo = getSpInfo(item);*/
Item item = new Item();
if (ruMain.getWlh() != null) {
TbKucun kucun = getKucun(item);
if (kucun.getWlh() == null) {
/*insert("insert into tb_kucun values('" + maxId
+ "','" + ruMain.getWlh() + "','"
+ ruMain.getHwname()
+ "','" + details.getSl() + "','"
+ ruMain.getGg() + "','"
+ details.getDw() + "','"
+ ruMain.getShelf()
+ "','" + ruMain.getHwwz() + "','"
+ ruMain.getHums() + "')");*/
String columnName="";
String cn2="";
TbKucun column = null;
columnName = ruMain.getWlh();// 为“商品信息”的实例赋值
column = new TbKucun(columnName);
String column1= (String) column.getWlh();
ResultSet set=Dao
.query("select * from tb_kucun where wlh='" +column1+ "'");
try {
if (set.next()) {
TbKucun kucun1 = new TbKucun();
String column2 = set.getString("kcsl");
cn2=column2;
Integer sl = Integer.valueOf(cn2) + details.getSl();
update("update tb_kucun set kcsl=" + sl + " where wlh='"
+ column1 + "'");
}
else {
insert("insert into tb_kucun values('" + maxId
+ "','" + ruMain.getWlh() + "','"
+ ruMain.getHwname()
+ "','" + details.getSl() + "','"
+ ruMain.getGg() + "','"
+ details.getDw() + "','"
+ ruMain.getShelf()
+ "','" + ruMain.getHwwz() + "','"
+ ruMain.getHums() + "')");
}
}
catch (SQLException e1) {
e1.printStackTrace();
}
}
}
}
conn.commit();
conn.setAutoCommit(autoCommit);
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return true;
}