Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public static int degreesOfSeperation(int musid) throws Exception{
  2. int deg = 0;
  3.  
  4. //Statement to create the temporary table if it doesn't exist
  5. PreparedStatement t = getConnection().prepareStatement(
  6. "Create table if not exists degreeofsep(" +
  7. "id int primary key, deg int, name varchar(255));");
  8. t.execute();
  9.  
  10. //Statement to get the name of the person who has the musid
  11. PreparedStatement getName = getConnection().prepareStatement(
  12. ("Select p.name From Person p Where p.id = ?"));
  13. getName.setInt(1, musid);
  14. ResultSet theName = getName.executeQuery();
  15.  
  16. while (theName.next()) {
  17. //Insert initial data into the table
  18. PreparedStatement start = getConnection().prepareStatement(
  19. "Insert into degreeofsep values(?, ?,"
  20. + theName.getString("name"));
  21.  
  22. start.setInt(1, musid);
  23. start.setInt(2, deg);
  24. start.execute();
  25. }
  26.  
  27.  
  28. //Query everyone that exists in a band.
  29. PreparedStatement ps = getConnection().prepareStatement
  30. ("select distinct p.name, p.id from Person p, memberOf m, Band b where " +
  31. "? = m.person and m.band = b.id");
  32. //Set the parameter.
  33. ps.setInt(1, musid);
  34.  
  35.  
  36.  
  37. //("Select person From memberOf Where band = " +
  38. // "(Select band From memberOf Where person = ?)");
  39. //The comment above works if a person is only part of one band, which is not true.
  40.  
  41. //Execute the query.
  42. ResultSet rs = ps.executeQuery();
  43. while (rs.next()) {
  44. //System.out.println(rs.getString("name"));
  45. }
  46. return 2;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement