public java.util.LinkedList<Pic> getPicsForUser(String User) { java.util.LinkedList<Pic> Pics = new java.util.LinkedList<>(); Session session = cluster.connect("instagrAndrew"); PreparedStatement ps = session.prepare("select picid, hashtag, pic_added from userpiclist where user =?"); ResultSet rs = null; BoundStatement boundStatement = new BoundStatement(ps); rs = session.execute( // this is where the query is executed boundStatement.bind( // here you are binding the 'boundStatement' User)); if (rs.isExhausted()) { System.out.println("No Images returned"); return null; } else { for (Row row : rs) { Pic pic = new Pic(); java.util.UUID UUID = row.getUUID("picid"); Date d = row.getDate("pic_added"); java.sql.Timestamp tmp = new java.sql.Timestamp(d.getTime()); pic.setUUID(UUID); pic.setDate(tmp); String ht = row.getString("hashtag"); if (ht != null) { pic.setHashtag(ht); } Pics.add(pic); } } return Pics; }
public java.util.LinkedList<Pic> getMatchingPics(String searched) { java.util.LinkedList<Pic> picList = new java.util.LinkedList<Pic>(); Session session = cluster.connect("instagrAndrew"); PreparedStatement ps = session.prepare("select * from userpicList"); ResultSet rs = null; BoundStatement boundStatement = new BoundStatement(ps); rs = session.execute(boundStatement); if (rs.isExhausted()) { System.out.println("No Images returned"); return new java.util.LinkedList<Pic>(); } else { for (Row row : rs) { String fullString = row.getString("hashtag"); UUID uuid = row.getUUID("picId"); String us = row.getString("user"); Date d = row.getDate("pic_added"); java.sql.Timestamp tmp = new java.sql.Timestamp(d.getTime()); String[] tags; try { tags = fullString.split(","); } catch (Exception ex) { tags = null; } if (tags != null) { for (int i = 0; i < tags.length; i++) { if (tags[i].toLowerCase().equals(searched.toLowerCase())) { Pic toAdd = new Pic(); toAdd.setUUID(uuid); toAdd.setDate(tmp); toAdd.setUser(us); toAdd.setHashtag(fullString); picList.add(toAdd); break; } } } } } return picList; }