Devrath N D
Devrath N D

Reputation: 711

DB2 Error SQLCODE=-103, SQLSTATE=42604

I am trying to update a table, but it isn't working and giving this sql error.

//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);

Upvotes: 0

Views: 20740

Answers (2)

Robert Co
Robert Co

Reputation: 1715

You are missing a space in before the WHERE clause, which messed up your 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!"

Upvotes: 3

Dan Bracuk
Dan Bracuk

Reputation: 20804

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.

Upvotes: 1

Related Questions