Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Method that finds the degrees of seperation from the musician
- //with the the given musid. Since I couldn't figure out how to
- public static int degreesOfSeperation(int musid) throws Exception{
- return degreesOfSeperationHelper(musid, 0);
- }
- //Helper method to count the degrees of seperation
- public static int degreesOfSeperationHelper(int musid, int deg) throws Exception{
- //Statement to create the temporary table if it doesn't exist
- PreparedStatement t = getConnection().prepareStatement(
- "Create table if not exists degreeofsep(" +
- "id int primary key, deg int, name varchar(255));");
- t.execute();
- //Statement to get the name of the person who has the musid
- PreparedStatement getName = getConnection().prepareStatement(
- ("Select p.name From Person p Where p.id = ?"));
- getName.setInt(1, musid);
- ResultSet theName = getName.executeQuery();
- while (theName.next()) {
- //Insert initial data into the table
- PreparedStatement start = getConnection().prepareStatement(
- "Insert into degreeofsep values(?, ?," + theName.getString("name"));
- start.setInt(1, musid);
- start.setInt(2, deg);
- start.execute();
- }
- //Query everyone that exists in a band.
- PreparedStatement ps = getConnection().prepareStatement
- ("select distinct p.name, p.id from Person p, memberOf m, Band b where " +
- "? = m.person and m.band = b.id");
- //Set the parameter.
- ps.setInt(1, musid);
- //("Select person From memberOf Where band = " +
- // "(Select band From memberOf Where person = ?)");
- //The comment above works if a person is only part of one band, which is not true.
- //Execute the query.
- ////ResultSet rs = ps.executeQuery();
- //while (rs.next()) {
- //System.out.println(rs.getString("name"));
- //}
- return 2;
- //}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement