Buggy code:
public class Order { private static JsonObjectBuilder JSONOrder ( ResultSet rs , JsonObjectBuilder order ) throws Exception { } private static JsonObjectBuilder JSONOrder ( int orderid , JsonObjectBuilder order ) throws Exception { } private static void JSONOrderItems ( int orderid , JsonArrayBuilder items , JsonObjectBuilder order ) throws Exception { } public static String details ( int authcid , int isAdmin , final int orderid ) { } public static String orders ( String start , String end , String span ) { } public static String latest ( int limit , int offset ) { } public static String add ( final int sessionCid , JsonObject payload ) { JsonObjectBuilder result = Json . createObjectBuilder ( ) ; JsonObjectBuilder newOrder = Json . createObjectBuilder ( ) ; JsonArrayBuilder newItems = Json . createArrayBuilder ( ) ; JsonObject order = payload . getJsonObject ( "order" ) ; String addr = order . getString ( "address" ) ; final int cid = Integer . parseInt ( order . getString ( "customer" ) ) ; Connector con = null ; try { con = new Connector ( ) ; } catch ( Exception e ) { if ( con != null ) con . closeConnection ( ) ; return null ; } try { <START_BUG> String sql = ( "SELECT<seq2seq4repair_space>B.isbn,<seq2seq4repair_space>B.title<seq2seq4repair_space>FROM<seq2seq4repair_space>Book<seq2seq4repair_space>B,<seq2seq4repair_space>Cart<seq2seq4repair_space>C<seq2seq4repair_space>WHERE<seq2seq4repair_space>C.cid<seq2seq4repair_space>=<seq2seq4repair_space>" + cid ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>B.isbn<seq2seq4repair_space>=<seq2seq4repair_space>C.isbn<seq2seq4repair_space>AND<seq2seq4repair_space>B.copies<seq2seq4repair_space><<seq2seq4repair_space>C.amount" ; <END_BUG> ResultSet rs = con . stmt . executeQuery ( sql ) ; if ( rs . next ( ) ) { System . out . print ( "No<seq2seq4repair_space>enough<seq2seq4repair_space>books<seq2seq4repair_space>" ) ; System . out . println ( rs . getString ( "title" ) ) ; if ( con != null ) con . closeConnection ( ) ; return null ; } sql = ( ( ( ( ( "UPDATE<seq2seq4repair_space>Book<seq2seq4repair_space>SET<seq2seq4repair_space>copies<seq2seq4repair_space>=<seq2seq4repair_space>copies<seq2seq4repair_space>-<seq2seq4repair_space>" + "(SELECT<seq2seq4repair_space>C.amount<seq2seq4repair_space>FROM<seq2seq4repair_space>Cart<seq2seq4repair_space>C<seq2seq4repair_space>WHERE<seq2seq4repair_space>Book.isbn<seq2seq4repair_space>=<seq2seq4repair_space>C.isbn<seq2seq4repair_space>AND<seq2seq4repair_space>C.cid<seq2seq4repair_space>=<seq2seq4repair_space>" ) + cid ) + ")<seq2seq4repair_space>" ) + "WHERE<seq2seq4repair_space>Book.isbn<seq2seq4repair_space>IN<seq2seq4repair_space>(SELECT<seq2seq4repair_space>C.isbn<seq2seq4repair_space>FROM<seq2seq4repair_space>Cart<seq2seq4repair_space>C<seq2seq4repair_space>WHERE<seq2seq4repair_space>C.cid<seq2seq4repair_space>=<seq2seq4repair_space>" ) + cid ) + ")" ; System . err . println ( sql ) ; con . stmt . execute ( sql ) ; sql = ( ( ( "INSERT<seq2seq4repair_space>INTO<seq2seq4repair_space>Orders<seq2seq4repair_space>(time,<seq2seq4repair_space>cid,<seq2seq4repair_space>addr)<seq2seq4repair_space>VALUES<seq2seq4repair_space>(NOW(),<seq2seq4repair_space>" + cid ) + ",<seq2seq4repair_space>'" ) + addr ) + "')" ; System . err . println ( sql ) ; con . stmt . execute ( sql ) ; sql = "SELECT<seq2seq4repair_space>LAST_INSERT_ID()<seq2seq4repair_space>AS<seq2seq4repair_space>orderid" ; rs = con . stmt . executeQuery ( sql ) ; rs . next ( ) ; int orderid = rs . getInt ( "orderid" ) ; sql = ( "INSERT<seq2seq4repair_space>INTO<seq2seq4repair_space>ItemInOrder<seq2seq4repair_space>(orderid,<seq2seq4repair_space>isbn,<seq2seq4repair_space>price,<seq2seq4repair_space>amount)<seq2seq4repair_space>" + ( "SELECT<seq2seq4repair_space>LAST_INSERT_ID(),<seq2seq4repair_space>C.isbn,<seq2seq4repair_space>B.price,<seq2seq4repair_space>C.amount<seq2seq4repair_space>FROM<seq2seq4repair_space>Cart<seq2seq4repair_space>C,<seq2seq4repair_space>Book<seq2seq4repair_space>B<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "C.isbn<seq2seq4repair_space>=<seq2seq4repair_space>B.isbn<seq2seq4repair_space>AND<seq2seq4repair_space>C.cid<seq2seq4repair_space>=<seq2seq4repair_space>" ) ) + cid ; System . err . println ( sql ) ; con . stmt . execute ( sql ) ; sql = "DELETE<seq2seq4repair_space>FROM<seq2seq4repair_space>Cart<seq2seq4repair_space>WHERE<seq2seq4repair_space>cid<seq2seq4repair_space>=<seq2seq4repair_space>" + cid ; System . err . println ( sql ) ; con . stmt . execute ( sql ) ; newOrder = Order . JSONOrder ( orderid , newOrder ) ; Order . JSONOrderItems ( orderid , newItems , newOrder ) ; result . add ( "order" , newOrder ) ; result . add ( "orderItems" , newItems ) ; if ( con != null ) con . closeConnection ( ) ; return result . build ( ) . toString ( ) ; } catch ( Exception e ) { System . out . println ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>update" ) ; System . err . println ( e . getMessage ( ) ) ; if ( con != null ) con . closeConnection ( ) ; return null ; } } public static String add2Cart ( final int sessionCid , JsonObject payload ) { } public static String cart ( final int cid ) { } public static String cartDetails ( final int cid , String isbn ) { } No newline ; at end ; of file ; }

Fix:
String sql = ( "SELECT<seq2seq4repair_space>B.isbn,<seq2seq4repair_space>B.title<seq2seq4repair_space>FROM<seq2seq4repair_space>Book<seq2seq4repair_space>B,<seq2seq4repair_space>Cart<seq2seq4repair_space>C<seq2seq4repair_space>WHERE<seq2seq4repair_space>C.cid<seq2seq4repair_space>=<seq2seq4repair_space>" + cid ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>B.isbn<seq2seq4repair_space>=<seq2seq4repair_space>C.isbn<seq2seq4repair_space>AND<seq2seq4repair_space>(B.copies<seq2seq4repair_space><<seq2seq4repair_space>C.amount<seq2seq4repair_space>OR<seq2seq4repair_space>C.amount<seq2seq4repair_space><<seq2seq4repair_space>0)" ;