public String addtoCart(String memNo, int movieId) { String res = " "; ResultSet rs = null; PreparedStatement ps = null; try { // con = getConnection(); CustomerDBConnection c = new CustomerDBConnection(); String result = c.checkCart(memNo, movieId); if (result.equals("true")) { String result2 = c.decreaseQuantity(movieId); if (result2.equals("true")) { String query = "Insert into cart(memNo,movieID) values(?,?)"; ps = con.prepareStatement(query); ps.setString(1, memNo); System.out.println(memNo); ps.setInt(2, movieId); System.out.println(movieId); ps.executeUpdate(); String query1 = "Select c.movieID,moviename,banner,description,releasedate,rent,category,quantity FROM movie m,cart c WHERE m.IdMovie = c.movieID and c.memNo=?"; ps = con.prepareStatement(query1); ps.setString(1, memNo); rs = ps.executeQuery(); while (rs.next()) { int movieID = rs.getInt(1); String name = rs.getString(2); String banner = rs.getString(3); String description = rs.getString(4); String releaseDate = rs.getString(5); String rent = rs.getString(6); String cat = rs.getString(7); String quant = rs.getString(8); res += movieID + ";" + name + ";" + banner + ";" + description + ";" + releaseDate + ";" + cat + ";" + quant + "##"; } } } else { res = "false"; } } catch (Exception e) { e.printStackTrace(); } return res; }