2013-06-28 43 views
0

我正在嘗試根據用戶輸入的期望數量的數量更新我的「Shares Issued」列。從Oracle數據庫中減去並更新值JDBC

這裏是我的表(從Oracle數據庫中檢索數據):

Share_ID Company Shares Issued Price Per Share 
1   Google 4500000   871.52 
2   Apple 2300000   403.2 
3   IBM  3000000   195.07 
4   Tesco 70000   326.5 
5   Mcsft 850000   33.7 
6   Dell 770000   13.43 
7   Banks 100000   1440.4 
8   SONY 650000   20.4 
9   Marvel 20000   54.08 

而且我的形式在這裏的股份輸入數量的期望:

<form id="share_selection" action="buy_share_request" method="get"> 
    ... 
    ... 
    Amount of Shares <input type="text" size="9" name="shares_desired"></input> 
    <input type="submit" value=" Buy " name="submit"> 
</form> 

什麼樣的更新查詢我可以寫數據庫中發行的股票數量減去用戶的輸入嗎?

+0

是什麼#符號在您查詢的含義? –

+0

UPDATE table_name set shares_issued =(選擇shares_issued FROM table_name where share_id = $ {share_name}) - $ {shares_desired} – vcetinick

+0

我可以看到多個股票>您如何通過share_id? – Makky

回答

1

你會嘗試這樣的事情。(不是一個完整的代碼只是一般你會嘗試這樣)

int available_shares = select shares_issues from shares where shere_id=? 
int remaining_shares = available_shares - Integer.parseInt(request.getParameter("shares")); 

SQL查詢

updates shares set share_issued=remaining_shares where share_id=? 
+0

偉大的想法,謝謝! – user2297666

+0

歡迎您。 – Makky