Social Media User Database Managment
Social Media User Database Managment
Management-System
Project Overview
1. User's Friends details
2. User's Joined pages and groups
3. All pages and groups posts
4. User's All Posts like, Comments and who sharing post
Also who has Liked Comments of any posts
Problem statement
The top-performing social networking sites including Facebook and
Instagram require a perfect database design. Their user data,
authentication data, user preferences, links between profiles, individual
posts and everything else needs accurate mapping and conservation.
Abstract
The most common database designs for social networking sites include
quick reference functions, features for the addition and removal of social
media sites and channels to your own database and the ability to filter
sites based on multiple features.
This Project involves the management of big data from multiple sources.
Big data is like the bigfoot of the business world. However, you need to
rendezvous with the very basics of big data management if you want to
utilize your social media channels for marketing success. Once your
business profile is up and running on multiple channels, you will get
terabytes of data each day. There is no other way to manage this
monumental amount of information unless you can find a reliable
database or design one for yourself.
Functional requirement
Relational Database design
Query Processing & Query Optimization
SQL Concepts
PL/SQL Concepts
Basic Use of MySQL and Eclipse
Java Database Connectivity
User Table
In this section, we will design the User Table to store user
information. Below mentioned is the description of all the
columns of the User Table.
Id The unique id to identify the user.
First Name The first name of the user.
In this section, we will design the User Message Table to store the
user chat messages. Below mentioned is the description of all the
columns of the User Message Table.
In this section, we will design the User Post Table to store the user
posts. The sender might be required to allow the other users with
appropriate permissions to post on the user wall. Below mentioned is
the description of all the columns of the User Post Table.
ER Diagram
SQL
User Table
FUNCTION
CREATE DEFINER=`root`@`localhost` FUNCTION
`number_of_Comments`(P_ID INT) RETURNS int
BEGIN
declare count INT default 0;
SELECT count(*) from post_comments WHERE
post_comments.Post_ID = P_ID into count;
RETURN count;
END
NUMBER OF FRIENDS
CREATE DEFINER=`root`@`localhost` PROCEDURE `number_of_friends`()
BEGIN
SELECT User_ID,COUNT(DISTINCT Friend_ID)
FROM Friends
GROUP BY User_ID;
END
Full Post Details
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `social_media`.`full_posts_details` AS
SELECT
`po`.`Post_ID` AS `Post_ID`,
`po`.`Posted_User_ID` AS `Posted_User_ID`,
(SELECT
`u`.`First_name`
FROM
`social_media`.`users` `u`
WHERE
(`u`.`User_ID` = `po`.`Posted_User_ID`)) AS `Posted_Users_name`,
(SELECT
`u`.`AGE`
FROM
`social_media`.`users` `u`
WHERE
(`u`.`User_ID` = `po`.`Posted_User_ID`)) AS `Posted_Users_age`,
`po`.`Post_Date` AS `Post_Date`,
`po`.`Post_Content` AS `Post_Content`,
(SELECT
COUNT(0)
FROM
`social_media`.`post_likes` `pl`
WHERE
(`pl`.`Post_ID` = `po`.`Post_ID`)) AS `numbet_of_likes`,
(SELECT
COUNT(0)
FROM
`social_media`.`post_shares` `ps`
WHERE
(`ps`.`Post_ID` = `po`.`Post_ID`)) AS `numbet_of_shares`,
(SELECT
COUNT(0)
FROM
`social_media`.`post_comments` `pc`
WHERE
(`pc`.`Post_ID` = `po`.`Post_ID`)) AS `numbet_of_comments`
FROM
`social_media`.`posts` `po`
Front-END
Frontend Softwares used HTML HTML (HyperText Markup Language) is
the most basic building block of the Web. It defines the
meaning and structure of web content. Other technologies besides HTML are
generally used to
describe a web page's appearance/presentation (CSS) or functionality/behavior
(JavaScript).
"Hypertext" refers to links that connect web pages to one another, either within
a single website
or between websites. Links are a fundamental aspect of the Web. By uploading
content to the
Internet and linking it to pages created by other people, you become an active
participant in the
World Wide Web.
CSS Cascading Style Sheets (CSS) is a stylesheet language used to describe
the presentation of a
document written in HTML or XML (including XML dialects such as SVG,
MathML or
XHTML). CSS describes how elements should be rendered on screen, on paper,
in speech, or on
other media.
CSS is among the core languages of the open web and is standardized across
Web browsers
according to W3C specifications. Previously, the development of various parts
of CSS
specification was done synchronously, which allowed the versioning of the
latest
recommendations. You might have heard about CSS1, CSS2.1, or even CSS3.
There will never
be a CSS3 or a CSS4; rather, everything is now CSS without a version number.
Screenshot
BACKEND
● MySQl ● Java Java and MySQL are two widely used technologies in the development of robust and
scalable backends for web applications. Java is a programming language that allows developers to
write code that can run on various platforms, making it a popular choice for creating web
applications. With the help of various frameworks like Spring and Hibernate, Java can be used to
develop efficient and reliable backends. MySQL, on the other hand, is a popular open-source
relational database management system that is known for its speed, reliability, and scalability. It is
widely used for storing and retrieving data for web applications. When used together, Java and
MySQL can form a powerful combination for building high-performance backends for web
applications. Java provides the ability to write complex logic and algorithms, while MySQL enables
the storage and retrieval of large amounts of data quickly and efficiently. By utilizing the JDBC API,
Java can easily connect to a MySQL database and execute queries, making it an ideal language for
interacting with MySQL. Additionally, various tools and frameworks like JPA (Java Persistence API)
and Hibernate make it easier to manage the interaction between Java and MySQL.
JAVA CODE
/**
*
*/
package dbms;
import java.sql.*;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;
/**
* @author Shubham
*
*/
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,uName,pass);
Statement st=con.createStatement();
ResultSet rs;
PreparedStatement std=con.prepareStatement(query);;
case 5:
try {
query ="update users set Pass_word= ? where User_ID = ?";
std=con.prepareStatement(query);
System.out.println("Enter user id who want to change
password");
id=inpu.nextInt();
System.out.println("Enter new password ");
String p=inpu.next();
std.setString(1, p);
std.setInt(2, id);
cnt= std.executeUpdate();
System.out.print(cnt+" row/s affected !!! \n");
}
catch(Exception e) {
System.out.println(e);
}
break;
case 6:
try {
query="CALL `social_media`.`number_of_friends`()";
rs=st.executeQuery(query);
System.out.println("USER_ID |
COUNT_OF_FRIENDS");
while(rs.next()) {
String userdata=rs.getInt(1)+" | "+rs.getInt(2);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println(e);
}
break;
case 7:
try {
System.out.println("enter a post_id for which you want to
see number of comments");
String p=inpu.next();
query="SELECT number_of_Comments("+p+")";
rs=st.executeQuery(query);
while(rs.next()) {
System.out.println("number of comments on
post_id "+p+" are "+rs.getInt(1));
}
}catch(Exception e) {
System.out.println(e);
}
break;
case 8:
try {
query="SELECT * from full_profile_of_users";
rs=st.executeQuery(query);
System.out.println("User_ID | Email_ID | First_name |
DOB | number_of_friends | number_of_pages | number_of_posts");
while(rs.next()) {
String userdata=rs.getInt(1)+" | "+rs.getString(2)+" |
"+rs.getString(3)+" | "+rs.getString(4)+" | "+rs.getInt(5)+" | "+rs.getInt(6)+" | "+rs.getInt(7);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println(e);
}
break;
case 9:
try {
query="SELECT * from full_posts_details";
rs=st.executeQuery(query);
System.out.println("POST_ID | USER_ID |
USER_NAME | USER_AGE | POSTED_DATE | POST_CONTENT | POST_LIKES |
POST_SHARES | POST_COMMENTS ");
while(rs.next()) {
String userdata=rs.getInt(1)+" | "+rs.getInt(2)+" |
"+rs.getString(3)+" | "+rs.getInt(4)+" | "+rs.getString(5)+" | "+rs.getString(6)+" |
"+rs.getInt(7)+" | "+rs.getInt(8)+" | "+rs.getInt(9);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println(e);
}
break;
case 10:
try {
query="SELECT
po.Post_ID,po.Post_content,po.Post_Date,pc.Comment_ID,pc.Comment_Content,pc.Comme
nted_Date from posts as po natural join post_comments as pc order by po.Post_ID
asc,pc.Comment_ID asc";
rs=st.executeQuery(query);
System.out.println("POST_ID | POST_CONTENT |
POSTED_DATE | COMMENT_ID | COMMENT_CONTENT | COMMENT_DATE");
while(rs.next()) {
String userdata=rs.getInt(1)+" |
"+rs.getString(2)+" | "+rs.getString(3)+" | "+rs.getInt(4)+" | "+rs.getString(5)+" |
"+rs.getString(6);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println();
}
break;
case 11:
try {
query="select
f1.User_ID,u1.First_name,u1.Gender,f1.Friend_ID,u2.First_name,u2.Gender from friends as
f1 natural join users as u1,users as u2 where f1.Friend_ID=u2.User_ID order by f1.User_id
asc,f1.friend_id asc";
rs=st.executeQuery(query);
System.out.println("USER_ID | FIRST_NAME |
GENDER | FRIEND_ID | FRIEND_NAME | FRIEND_GENDER");
while(rs.next()) {
String userdata=rs.getInt(1)+" |
"+rs.getString(2)+" | "+rs.getString(3)+" | "+rs.getInt(4)+" | "+rs.getString(5)+" |
"+rs.getString(6);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println();
}
break;
case 12:
try {
query="select
pg.Page_ID,pg.Page_name,pg.Page_Content,u.User_ID,u.First_name,u.AGE from pages as
pg natural join page_likes as pl,users as u where pl.Page_User_ID=u.User_ID order by
pg.Page_ID asc,u.User_ID asc";
rs=st.executeQuery(query);
System.out.println("PAGE_ID | PAGE_NAME |
PAGE_CONTENT | USER_ID | FIRST_NAME | AGE");
while(rs.next()) {
String userdata=rs.getInt(1)+" |
"+rs.getString(2)+" | "+rs.getString(3)+" | "+rs.getInt(4)+" | "+rs.getString(5)+" |
"+rs.getInt(6);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println();
}
break;
case 13:
try {
query ="delete from post_comments where
Comment_ID = ?";
std=con.prepareStatement(query);
System.out.println("Enter comment id which you want
to delete");
id=inpu.nextInt();
std.setInt(1, id);
cnt= std.executeUpdate();
System.out.print(cnt+" row/s affected !!! \n");
try {
query="select * from comments_like order by
comment_ID";
rs=st.executeQuery(query);
System.out.println("COMMENT_ID |
COMMENT_LIKED_USER_ID");
while(rs.next()) {
String userdata=rs.getInt(1)+" |
"+rs.getString(2);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println();
}
}
catch(Exception e) {
System.out.println(e);
}
break;
case 14:
try {
query="select
co.Post_ID,co.Comment_ID,co.Comment_Content,cl.Comment_liked_User_ID,u.First_name
from post_comments as co natural join comments_like as cl, users as u where
cl.Comment_liked_User_ID=u.User_ID order by co.Post_ID
asc,co.Comment_ID,cl.Comment_liked_User_ID;";
rs=st.executeQuery(query);
System.out.println("POST_ID | COMMENT_ID |
COMMENT_CONTENT | COMMENT_LIKED_USER_ID | FIRST_NAME");
while(rs.next()) {
String userdata=rs.getInt(1)+" | "+rs.getInt(2)+" |
"+rs.getString(3)+" | "+rs.getInt(4)+" | "+rs.getString(5);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println();
}
break;
case 15:
try {
query="select
co.Post_ID,co.Comment_ID,co.Comment_Content,cl.Comment_liked_User_ID,u.First_name
from post_comments as co natural join comments_like as cl, users as u where
cl.Comment_liked_User_ID=u.User_ID order by co.Post_ID
asc,co.Comment_ID,cl.Comment_liked_User_ID;";
rs=st.executeQuery(query);
System.out.println("POST_ID | COMMENT_ID |
COMMENT_CONTENT | COMMENT_LIKED_USER_ID | FIRST_NAME");
while(rs.next()) {
String userdata=rs.getInt(1)+" | "+rs.getInt(2)+" |
"+rs.getString(3)+" | "+rs.getInt(4)+" | "+rs.getString(5);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println();
}
break;
System.out.println("\n******************** \n");
}
st.close();
con.close();
}