SOS ! 关于statement的问题?45分,我能给的最大分数??大虾救命
luoql 2002-01-01 12:35:02 stmt = con.createStatement();
stmt.execute("INSERT INTO myTable ( 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 = ?");
rs = stmt.executeQuery("select * from products where prod_id = "+theProd);
pstmt.setString(1,theProd);
rs = pstmt.executeQuery();
rs.next() ;
float currentStock = rs.getFloat("stock");
currentStock = currentStock + theQuantity;
pstmt1= con.prepareStatement("UPDATE products set stock = "+currentStock+" where prod_id= ?");
pstmt1.setString(1,theProd);
pstmt1.executeUpdate();
con.commit();
我上面的代码出现连接占线错误,我调试了一下,是因为有两个prepareStatement 对同一个表操作的原因,但我必须先从products表中取出currentStock,更新后又写入到products表中,而且theProd又是字符串的参数,我怎么搞定它,大虾帮帮忙!!