java DB2 错误 SQLCODE=-103,SQLSTATE=42604
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15851921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DB2 Error SQLCODE=-103, SQLSTATE=42604
提问by Devrath N D
I am trying to update a table, but it isn't working and giving this sql error.
我正在尝试更新一个表,但它不起作用并给出了这个 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);
回答by Robert Co
You are missing a space in before the WHERE
clause, which messed up your stknv
.
您在WHERE
子句之前缺少一个空格,这弄乱了您的stknv
.
" WHERE \"StockBuyId\" = "+ stkbid);
I think it's an obligation of any poster to remind you that you should use parametrized query. So I shall do the same.
我认为任何海报都有义务提醒您应该使用参数化查询。所以我也会这样做。
"Please use parametrized query!"
“请使用参数化查询!”
回答by Dan Bracuk
The query that is works has a quote at the end:
有效的查询在末尾有一个引号:
" WHERE \"StockBuyId\" = '"+ stkbid + "'");
The one that fails does not
失败者不
"WHERE \"StockBuyId\" = "+ stkbid);
That might have something to do with it.
这可能与它有关。