public static boolean deleteUser(String user) { Connection con = null; CallableStatement cs = null; try { con = LoginBean.getConnection(); Statement st = null; Statement st2 = null; Statement st4 = null; st2 = con.createStatement(); String sql4 = ("delete from items where seller = '" + user + "';"); st2.execute(sql4); st4 = con.createStatement(); String sql5 = ("delete from bids where bidder = '" + user + "';"); st4.execute(sql5); st = con.createStatement(); String sql3 = ("delete from users where username = '******';"); st.execute(sql3); return true; } catch (Exception ex) { System.out.println(ex.getMessage()); return false; } finally { try { cs.close(); con.close(); } catch (Exception ex) { } } }
/* * Delete item */ public static boolean delete(int itemid) { Connection con = null; CallableStatement cs = null; try { con = LoginBean.getConnection(); Statement st = null; st = con.createStatement(); String sql3 = ("delete from items where itemid = " + itemid + ";"); st.execute(sql3); Statement st2 = null; st2 = con.createStatement(); String sqll3 = ("delete from bids where itemid = " + itemid + ";"); st2.execute(sqll3); return true; } catch (Exception ex) { System.out.println(ex.getMessage()); return false; } finally { try { cs.close(); con.close(); } catch (Exception ex) { } } }
public static boolean updateUser( String user, String fname, String lname, String address, String phone) { Connection con = null; CallableStatement cs = null; try { con = LoginBean.getConnection(); Statement st = null; st = con.createStatement(); Statement st2 = null; st2 = con.createStatement(); Statement st3 = null; st3 = con.createStatement(); Statement st4 = null; st4 = con.createStatement(); System.out.println(fname); System.out.println(lname); System.out.println(address); System.out.println(phone); if (fname != null) { String sql3 = ("update users set fname= '" + fname + "' where username = '******';"); st.execute(sql3); } if (lname != null) { String sql4 = ("update users set lname= '" + lname + "' where username = '******';"); st2.execute(sql4); } if (address != null) { String sql5 = ("update users set address= '" + address + "' where username = '******';"); st3.execute(sql5); } if (phone != null) { String sql6 = ("update users set phone= '" + phone + "' where username = '******';"); st4.execute(sql6); } return true; } catch (Exception ex) { System.out.println(ex.getMessage()); return false; } finally { try { cs.close(); con.close(); } catch (Exception ex) { } } }
public static Boolean bidForItem(String buyer, int itemid, int bidprice) { Connection con = null; Statement s1 = null; Statement stmt2 = null; Statement stmt3 = null; Statement st4 = null; Statement stmt5 = null; Statement st6 = null; try { con = LoginBean.getConnection(); con.setAutoCommit(false); s1 = con.createStatement(); ResultSet r6 = s1.executeQuery( "Select startPrice, maxBid, seller from items where itemID=" + itemid + ";"); r6.next(); int initPrice = r6.getInt(1); int mbid = r6.getInt(2); String seller = r6.getString(3); boolean validBid = true; if (bidprice < initPrice || bidprice <= mbid) { validBid = false; } System.out.println(buyer); System.out.println(seller); int match; match = buyer.compareTo(seller); if (match == 0) { validBid = false; } String empty = ""; int match2; match2 = buyer.compareTo(empty); if (match2 == 0) { validBid = false; } if (validBid) { stmt3 = con.createStatement(); String sql1 = "insert into bids(itemid, bidder, bidPrice) values(" + itemid + ", '" + buyer + "', " + bidprice + ");"; stmt3 = con.createStatement(); stmt3.execute(sql1); st4 = con.createStatement(); ResultSet r = st4.executeQuery( "select bidder, bidprice from bids where bidprice=(select max(bidprice) from bids where itemid =" + itemid + ");"); r.next(); String bidder = r.getString(1); int highestBid = r.getInt(2); System.out.println(bidder); System.out.println(highestBid); st6 = con.createStatement(); String sql3 = ("update items i, (select min(biddate) biddate from bids where itemid=" + itemid + ")m set enddate = adddate(biddate,1) where itemid =" + itemid + ";"); st6.execute(sql3); st6 = con.createStatement(); stmt2 = con.createStatement(); String sql2 = ("update items set maxBid = " + highestBid + " where itemid = " + itemid + ";"); stmt2.execute(sql2); stmt2 = con.createStatement(); stmt5 = con.createStatement(); String sql4 = ("update items set buyer = '" + bidder + "' where itemid = " + itemid + ";"); stmt5.execute(sql4); stmt5 = con.createStatement(); } else { return false; } con.commit(); return true; } catch (Exception ex) { System.out.println(ex.getMessage()); return false; } finally { try { if (con != null) con.close(); } catch (Exception ex) { } } }