0

我正在尝试更新一个表,但它不工作并给出了这个 sql 错误。

//Updating Buy Table
Integer stkbid = Integer.parseInt(request.getParameter("stockBid"));
System.out.println("stock buy id : " + stkbid);
//get buy details
PreparedStatement stmtbuy = conn.prepareStatement(
        "SELECT \"StockSymbol\", \"Unit\", \"Price\", \"ClearingFee\", \"StampDuty\", \"BrokerFee\""  + 
        "FROM SPM.\"StockBuy\" WHERE \"StockBuyId\" = '"+ stkbid + "'");

System.out.println("Got stock buy details");

ResultSet rs=stmtbuy.executeQuery();
rs.next();
//String stkcode = rs.getString("StockSymbol");
Integer stkunit =  Integer.parseInt(rs.getString("Unit"));
stkunit -= stock.getStockUnit();
Double stkprice = Double.parseDouble(rs.getString("Price"));
Double stkclear = Double.parseDouble(rs.getString("ClearingFee"));
Double stksd = Double.parseDouble(rs.getString("StampDuty"));
Double stkbfee = Double.parseDouble(rs.getString("BrokerFee"));
Double stkval = stkunit * stkprice;
Double stknv = stkval + stkval * (stkclear + stksd + stkbfee);

System.out.println(stknv);

PreparedStatement stmtbuy1 = conn.prepareStatement(
        "UPDATE SPM.\"StockBuy\" SET \"Unit\" = " + stkunit + ", \"Value\" = " + stkval + ", \"NetValue\" = " + stknv + 
        "WHERE \"StockBuyId\" = "+ stkbid);
4

2 回答 2

3

您在WHERE子句之前缺少一个空格,这弄乱了您的stknv.

" WHERE \"StockBuyId\" = "+ stkbid);

我认为任何海报都有义务提醒您应该使用参数化查询。所以我也会这样做。

"请使用参数化查询! "

于 2013-04-06T22:18:28.407 回答
1

有效的查询最后有一个引号:

" WHERE \"StockBuyId\" = '"+ stkbid + "'");

失败的不

    "WHERE \"StockBuyId\" = "+ stkbid);

这可能与它有关。

于 2013-04-06T16:53:04.050 回答