Code with Finding: |
class SocialNetworkDatabasePosts {
/**
* Verifies whether a post exists in the given board (and region).
*/
public static Boolean postExists(Connection conn, String boardName, String regionName, int postNum) {
PreparedStatement pstmt = null;
ResultSet postResult = null;
String getPost = "";
if (boardName.equals("freeforall")) {
getPost = "SELECT * FROM freeforall.posts " +
"WHERE pid = ?";
}
else {
getPost = "SELECT * FROM " + boardName + ".posts " +
"WHERE pid = ? AND rname = ?";
}
Boolean postExists = null;
try {
pstmt = conn.prepareStatement(getPost);
pstmt.setInt(1, postNum);
if (!boardName.equals("freeforall")) {
pstmt.setString(2, regionName);
}
postResult = pstmt.executeQuery();
postExists = new Boolean(postResult.next());
}
catch (SQLException e) {
e.printStackTrace();
System.out.println(e.getSQLState());
}
finally {
DBManager.closePreparedStatement(pstmt);
}
return postExists;
}
}
class SocialNetworkDatabasePosts {
public static int addFFAParticipipant(Connection conn, int post, String username, String priv) {
int status = 0;
String query = "INSERT INTO freeforall.postprivileges (pid, username, privilege) " +
"VALUES (?, ?, ?)";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(query);
pstmt.setInt(1, post);
pstmt.setString(2, username);
pstmt.setString(3, priv);
status = pstmt.executeUpdate();
} catch (SQLException e) {
status = 0;
}
return status;
}
}
|