0% found this document useful (0 votes)
737 views25 pages

Social Media User Database Managment

This document outlines the design of a social media database management system. It includes tables for users, friends, followers, messages, and posts. It describes the columns for each table along with their purpose. It also includes sample SQL code for creating the tables and defining foreign key relationships. Stored procedures are defined to calculate the number of friends and retrieve full post details including comments and likes. An entity relationship diagram is also included to visualize the relationships between tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
737 views25 pages

Social Media User Database Managment

This document outlines the design of a social media database management system. It includes tables for users, friends, followers, messages, and posts. It describes the columns for each table along with their purpose. It also includes sample SQL code for creating the tables and defining foreign key relationships. Stored procedures are defined to calculate the number of friends and retrieve full post details including comments and likes. An entity relationship diagram is also included to visualize the relationships between tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Social-Media-Users-Database-

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.

Middle The middle name of the user.


Name
Last Name The last name of the user.
The mobile number of the user. It can be used
Mobile
for login and registration purposes.
The email of the user. It can be used for login
Email
and registration purposes.
The password hash generated by the
Password
appropriate algorithm. We must avoid storing
Hash
plain or encrypted passwords.
Registered This column can be used to calculate the life
At of the user with the application.
It can be used to identify the last login of the
Last Login
user.
Intro The brief introduction of the User.
Profile User details.

The project involves different segments of database for every


different functionalities:
• Stored procedures
• Users
• Table
• Views
• Comments
• Likes
• Shares
• Number of Friends
• Post
1. Like
2. Share
3. Comment
User Friend Table
In this section, we will design the User Friend Table to store
the user friends. The friend status can be used to track the
friendship status and type can be used to specify the type of
friendship. Below mentioned is the description of all the
columns of the User Friend Table.

Id The unique id to identify the friendship.


The user id to identify the user who initiated the
Source Id
friendship.
Target Id The user id of the friend.
The type to classify friends. It can be School,
Type
College, or Acquaintance.
Status The status can be New, Rejected, or Active.
Created It stores the date and time at which the friend
At request was initiated.
Updated It stores the date and time at which the friend
At request was updated.
Notes It stores the notes specific to the friendship.

User Follower Table


In this section, we will design the User Follower Table to store the
user followers. The follower type can be used to specify the type of
follower among Like, Dislike, or Follow. Below mentioned is the
description of all the columns of the User Follower Table.
Id The unique id to identify the follower.
Source Id The user id to identify the follower user.
Target Id The user id to identify the following user.
Type The type to classify followers. It can be Like, Dislike, or
Follow.
It stores the date and time at which the follower was
Created At
created.
Updated It stores the date and time at which the follower was
At updated.

User Message Table

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.

Id The unique id to identify the message.


Source Id The user id to identify the sender.
Target Id The user id to identify the receiver.
Message The message body.
It stores the date and time at which the message was
Created At
created.
Updated It stores the date and time at which the message was
At updated.

User Post 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.

Id The unique id to identify the post.


User Id The user id to identify the corresponding user.
Sender Id The sender id to identify the corresponding sender.
Message The message body.
Created At It stores the date and time at which the post was created.
Updated At It stores the date and time at which the post was updated.

ER Diagram
SQL
User Table

CREATE TABLE `sns`.`user` (


`id` BIGINT NOT NULL AUTO_INCREMENT,
`firstName` VARCHAR(50) NULL DEFAULT NULL,
`middleName` VARCHAR(50) NULL DEFAULT NULL,
`lastName` VARCHAR(50) NULL DEFAULT NULL,
`username` VARCHAR(50) NULL DEFAULT NULL,
`mobile` VARCHAR(15) NULL,
`email` VARCHAR(50) NULL,
`passwordHash` VARCHAR(32) NOT NULL,
`registeredAt` DATETIME NOT NULL,
`lastLogin` DATETIME NULL DEFAULT NULL,
`intro` TINYTEXT NULL DEFAULT NULL,
`profile` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `uq_username` (`username` ASC),
UNIQUE INDEX `uq_mobile` (`mobile` ASC),
UNIQUE INDEX `uq_email` (`email` ASC) );
User Friend Table

CREATE TABLE `sns`.`user_friend` (


`id` BIGINT NOT NULL AUTO_INCREMENT,
`sourceId` BIGINT NOT NULL,
`targetId` BIGINT NOT NULL,
`type` SMALLINT NOT NULL DEFAULT 0,
`status` SMALLINT NOT NULL DEFAULT 0,
`createdAt` DATETIME NOT NULL,
`updatedAt` DATETIME NULL DEFAULT NULL,
`notes` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `idx_friend_source` (`sourceId` ASC),
CONSTRAINT `fk_friend_source`
FOREIGN KEY (`sourceId`)
REFERENCES `sns`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);

ALTER TABLE `sns`.`user_friend`


ADD INDEX `idx_friend_target` (`targetId` ASC);
ALTER TABLE `sns`.`user_friend`
ADD CONSTRAINT `fk_friend_target`
FOREIGN KEY (`targetId`)
REFERENCES `sns`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE `sns`.`user_friend` ADD UNIQUE `uq_friend`(`sourceId`,


`targetId`);

User Follower Table

CREATE TABLE `sns`.`user_follower` (


`id` BIGINT NOT NULL AUTO_INCREMENT,
`sourceId` BIGINT NOT NULL,
`targetId` BIGINT NOT NULL,
`type` SMALLINT NOT NULL DEFAULT 0,
`createdAt` DATETIME NOT NULL,
`updatedAt` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `idx_ufollower_source` (`sourceId` ASC),
CONSTRAINT `fk_ufollower_source`
FOREIGN KEY (`sourceId`)
REFERENCES `sns`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);

ALTER TABLE `sns`.`user_follower`


ADD INDEX `idx_ufollower_target` (`targetId` ASC);
ALTER TABLE `sns`.`user_follower`
ADD CONSTRAINT `fk_ufollower_target`
FOREIGN KEY (`targetId`)
REFERENCES `sns`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE `sns`.`user_follower` ADD UNIQUE


`uq_ufollower`(`sourceId`, `targetId`, `type`);

User Post Table

CREATE TABLE `sns`.`user_post` (


`id` BIGINT NOT NULL AUTO_INCREMENT,
`userId` BIGINT NOT NULL,
`senderId` BIGINT NOT NULL,
`message` TINYTEXT NULL DEFAULT NULL,
`createdAt` DATETIME NOT NULL,
`updatedAt` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `idx_upost_user` (`userId` ASC),
CONSTRAINT `fk_upost_user`
FOREIGN KEY (`userId`)
REFERENCES `sns`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);

ALTER TABLE `sns`.`user_post`


ADD INDEX `idx_upost_sender` (`senderId` ASC);
ALTER TABLE `sns`.`user_post`
ADD CONSTRAINT `fk_upost_sender`
FOREIGN KEY (`senderId`)
REFERENCES `sns`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

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
*
*/

public class Social_media {

public static void main(String[] args) throws Exception{


// TODO Auto-generated method stub
Scanner inpu=new Scanner(System.in);
String url="jdbc:mysql://localhost:3306/social_media";
String uName="DatabaseUserName";
String pass="YourPassword";
String query="select * from users";

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,uName,pass);
Statement st=con.createStatement();
ResultSet rs;
PreparedStatement std=con.prepareStatement(query);;

String options="enter 0 for finish process \n"


+"enter 1 for see users table \n"
+ "enter 2 for see pages table \n"
+ "enter 3 for insert data in users table \n"
+"enter 4 for delete data from users table \n"
+"enter 5 for update users password \n"
+"enter 6 for show all users number of friends ---using PL/SQL
PROCEDURES & CURSOR\n"
+"enter 7 for show number of comments on any post ----using SQL
FUNCTIONS \n"
+"enter 8 for see all users profiles,number of friends,connected pages,posts --
using CRATE VIEW \n"
+"enter 9 for see all posts details,posted user name,post likes,post shares,post
comments ---using CRATE VIEW\n"
+"enter 10 for see all comments using only post_id ---using natural join\n"
+"enter 11 for see list of friends name and User id and gender\n"
+"enter 12 for find all pages all members details ----using natural join \n"
+"enter 13 for delete any comment and see comment likes also delete\n"
+"enter 14 for see user who liked any post comments ---using joins\n";
boolean flag=true;
int opt=0,cnt=0,id;
while(flag) {
System.out.println(options);
opt=inpu.nextInt();
switch(opt) {
case 0:
flag=false;
break;
case 1:
try {
query="select * from users";
rs=st.executeQuery(query);
System.out.println("USER_ID | EMAIL_ID | PHONE_NO |
PASSWORD | FIRST_NAME | LAST_NAME | CITY | PINCODE | DOB | GENDER |
AGE");
while(rs.next()) {
String userdata=rs.getInt(1)+" | "+rs.getString(2)+" |
"+rs.getString(3)+" | "+rs.getString(4)+" | "+rs.getString(5)+" | "+rs.getString(6)+" |
"+rs.getString(7)+" | "+rs.getInt(8)+" | "+rs.getString(9)+" | "+rs.getString(10)+" |
"+rs.getInt(11);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println(e);
}
break;
case 2:
try {
query="select * from pages";
rs=st.executeQuery(query);
System.out.println("PAGE_ID | PAGE_NAME |
PAGE_CONTENT");
while(rs.next()) {
String userdata=rs.getInt(1)+" | "+rs.getString(2)+" |
"+rs.getString(3);
System.out.println(userdata);
}
}
catch(Exception e) {
System.out.println(e);
}
break;
case 3:
try {
query="insert into
users(Email_ID,Phone_No,Pass_word,First_name,Last_name,City,PinCode,DOB,Gender)
values (?,?,?,?,?,?,?,DATE ?,?)";
std=con.prepareStatement(query);
String
Emailid,phoneno,Password,firstname,lastname,city,dob,gender;
int pincode;
System.out.println("enter user email id ");
Emailid=inpu.next(); ((PreparedStatement) std).setString(1,Emailid);
System.out.println("enter user 10 digit phone no ");
phoneno=inpu.next(); ((PreparedStatement) std).setString(2,phoneno);
System.out.println("enter user password ");
Password=inpu.next(); ((PreparedStatement) std).setString(3,Password);
System.out.println("enter user first name ");
firstname=inpu.next(); ((PreparedStatement) std).setString(4,firstname);
System.out.println("enter user last name ");
lastname=inpu.next(); ((PreparedStatement) std).setString(5,lastname);
System.out.println("enter user city "); city=inpu.next();
((PreparedStatement) std).setString(6,city);
System.out.println("enter user pincode ");
pincode=inpu.nextInt(); ((PreparedStatement) std).setInt(7,pincode);
System.out.println("enter user date of birth in yyyy-mm-dd
format "); dob=inpu.next(); ((PreparedStatement) std).setString(8,dob);
System.out.println("enter user gender 'M' or 'F' ");
gender=inpu.next(); ((PreparedStatement) std).setString(9,gender);
cnt= (int) ((PreparedStatement) std).executeUpdate();
System.out.print(cnt+" row/s affected !!! \n");
}
catch(Exception e) {
System.out.println(e);
}
break;
case 4:
try {
query ="delete from users where User_ID = ?";
std=con.prepareStatement(query);
System.out.println("Enter user id which you want to delete");
id=inpu.nextInt();
std.setInt(1, id);
cnt= std.executeUpdate();
System.out.print(cnt+" row/s affected !!! \n");
}
catch(Exception e) {
System.out.println(e);
}
break;

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();
}

You might also like