con.setAutoCommit(false);stmt = con.createStatement();
stmt.execute("INSERT INTO " +tableStr+"( id,number,prod_id,quantity,price,unit,iDate) VALUES('"+theId+"','"+theNumber+"','"+theProd+"','"+theQuantity+"','"+thePrice+"','"+theUnit+"','"+sTheDate"')");
pstmt=con.prepareStatement("select * from products where prod_id = ?");
pstmt.setString(1,theProd);
rs = pstmt.executeQuery();
rs.next() ;
float currentStock = rs.getFloat("stock");
currentStock = currentStock + theQuantity;
pstmt= con.prepareStatement("UPDATE products set stock = "+currentStock+" where prod_id= ?");
pstmt.setString(1,theProd);
pstmt.executeUpdate();
//if(true) throw new SQLException();
con.commit();上面代码出错,说是连接占线导致另一个 hstmt,大虾教我,什么原因呀??
stmt.execute("INSERT INTO " +tableStr+"( id,number,prod_id,quantity,price,unit,iDate) VALUES('"+theId+"','"+theNumber+"','"+theProd+"','"+theQuantity+"','"+thePrice+"','"+theUnit+"','"+sTheDate"')");
pstmt=con.prepareStatement("select * from products where prod_id = ?");
pstmt.setString(1,theProd);
rs = pstmt.executeQuery();
rs.next() ;
float currentStock = rs.getFloat("stock");
currentStock = currentStock + theQuantity;
pstmt= con.prepareStatement("UPDATE products set stock = "+currentStock+" where prod_id= ?");
pstmt.setString(1,theProd);
pstmt.executeUpdate();
//if(true) throw new SQLException();
con.commit();上面代码出错,说是连接占线导致另一个 hstmt,大虾教我,什么原因呀??
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货