0% found this document useful (0 votes)
2 views28 pages

IT Project thors

The document contains a comprehensive overview of MySQL queries and Java programs, including their structure, explanations, and outputs. It also includes a bibliography of resources used for learning MySQL and Java, as well as an acknowledgment section expressing gratitude to contributors. The content serves as a guide for understanding and implementing various database queries and programming tasks.

Uploaded by

Narendra Giri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views28 pages

IT Project thors

The document contains a comprehensive overview of MySQL queries and Java programs, including their structure, explanations, and outputs. It also includes a bibliography of resources used for learning MySQL and Java, as well as an acknowledgment section expressing gratitude to contributors. The content serves as a guide for understanding and implementing various database queries and programming tasks.

Uploaded by

Narendra Giri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

MySQL Queries and their outputs:

Table Structure: Employees Table:

| id | name | age | department | salary |


|-----|-------------|-----|------------|--------|
| 1 | John Smith | 30 | HR | 50000 |
| 2 | Jane Doe | 25 | IT | 60000 |
| 3 | Robert Lee | 40 | Finance | 75000 |
| 4 | Emily Davis | 28 | IT | 65000 |
| 5 | Michael Roy | 35 | HR | 52000 |

1. Instruction: Display all columns from the employees table.

Query:

sql

SELECT * FROM employees;

Explanation: This query retrieves all columns and records from the employees
table.

Output:

| id | name | age | department | salary |


|-----|-------------|-----|------------|--------|
| 1 | John Smith | 30 | HR | 50000 |
| 2 | Jane Doe | 25 | IT | 60000 |
| 3 | Robert Lee | 40 | Finance | 75000 |
| 4 | Emily Davis | 28 | IT | 65000 |
| 5 | Michael Roy | 35 | HR | 52000 |

2. Instruction: Select only the name and age columns from the employees
table.
Query:

sql

SELECT name, age FROM employees;

Explanation: This query retrieves only the name and age columns of all
employees.

Output:

| name | age |
|-------------|-----|
| John Smith | 30 |
| Jane Doe | 25 |
| Robert Lee | 40 |
| Emily Davis | 28 |
| Michael Roy | 35 |

3. Instruction: Count the total number of records in the employees table.

Query:

sql

SELECT COUNT(*) FROM employees;

Explanation: This query counts the total number of rows in the employees
table.

Output:

| COUNT(*) |
|----------|
| 5 |

4. Instruction: Calculate the average salary of all employees.

Query:
sql

SELECT AVG(salary) FROM employees;

Explanation: This query calculates the average salary of all employees in the
table.

Output:

| AVG(salary) |
|-------------|
| 61400 |

5. Instruction: Retrieve the maximum salary from the employees table.

Query:

sql

SELECT MAX(salary) FROM employees;

Explanation: This query returns the highest salary in the employees table.

Output:

| MAX(salary) |
|-------------|
| 75000 |

6. Instruction: Retrieve the minimum salary from the employees table.

Query:
sql

SELECT MIN(salary) FROM employees;

Explanation: This query returns the lowest salary in the employees table.

Output:

| MIN(salary) |
|-------------|
| 50000 |

7. Instruction: Retrieve all employees from the IT department.

Query:

sql

SELECT * FROM employees WHERE department = 'IT';

Explanation: This query retrieves all employees who work in the IT department.

Output:

| id | name | age | department | salary |


|-----|-------------|-----|------------|--------|
| 2 | Jane Doe | 25 | IT | 60000 |
| 4 | Emily Davis | 28 | IT | 65000 |

8. Instruction: Retrieve distinct department names from the employees


table.

Query:
sql

SELECT DISTINCT department FROM employees;

Explanation: This query returns a list of unique department names from the
employees table.

Output:

| department |
|------------|
| HR |
| IT |
| Finance |

9. Instruction: Retrieve the names of employees older than 30.

Query:

sql

SELECT name FROM employees WHERE age > 30;

Explanation: This query retrieves the name of employees who are older than 30
years.

Output:

| name |
|-------------|
| Robert Lee |
| Michael Roy |

10. Instruction: Retrieve the names and salaries of employees ordered by


salary in descending order.

Query:

sql
SELECT name, salary FROM employees ORDER BY salary
DESC;

Explanation: This query retrieves the name and salary columns of all
employees, sorted in descending order of salary.

Output:

| name | salary |
|-------------|--------|
| Robert Lee | 75000 |
| Emily Davis | 65000 |
| Jane Doe | 60000 |
| Michael Roy | 52000 |
| John Smith | 50000 |

11. Instruction: Retrieve the first 3 records from the employees table.

Query:

sql

SELECT * FROM employees LIMIT 3;

Explanation: This query retrieves the first 3 records from the employees table.

Output:

| id | name | age | department | salary |


|-----|-------------|-----|------------|--------|
| 1 | John Smith | 30 | HR | 50000 |
| 2 | Jane Doe | 25 | IT | 60000 |
| 3 | Robert Lee | 40 | Finance | 75000 |
12. Instruction: Add a new employee record to the employees table.

Query:

sql

INSERT INTO employees (id, name, age, department,


salary)
VALUES (6, 'Alice Green', 27, 'HR', 48000);

Explanation: This query adds a new employee with id = 6, name = Alice


Green, and salary details.

Output (after running SELECT * FROM employees):

| id | name | age | department | salary |


|-----|-------------|-----|------------|--------|
| 1 | John Smith | 30 | HR | 50000 |
| 2 | Jane Doe | 25 | IT | 60000 |
| 3 | Robert Lee | 40 | Finance | 75000 |
| 4 | Emily Davis | 28 | IT | 65000 |
| 5 | Michael Roy | 35 | HR | 52000 |
| 6 | Alice Green | 27 | HR | 48000 |

13. Instruction: Update the salary of employee with id = 2 to 70000.

Query:

sql

UPDATE employees
SET salary = 70000
WHERE id = 2;

Explanation: This query updates the salary of the employee with id = 2 to


70000.

Output (after running SELECT * FROM employees):

| id | name | age | department | salary |


|-----|-------------|-----|------------|--------|
| 1 | John Smith | 30 | HR | 50000 |
| 2 | Jane Doe | 25 | IT | 70000 |
| 3 | Robert Lee | 40 | Finance | 75000 |
| 4 | Emily Davis | 28 | IT | 65000 |
| 5 | Michael Roy | 35 | HR | 52000 |
| 6 | Alice Green | 27 | HR | 48000 |

14. Instruction: Delete the employee record with id = 4.

Query:

sql

DELETE FROM employees


WHERE id = 4;

Explanation: This query deletes the employee with id = 4.

Output (after running SELECT * FROM employees):

| id | name | age | department | salary |


|-----|-------------|-----|------------|--------|
| 1 | John Smith | 30 | HR | 50000 |
| 2 | Jane Doe | 25 | IT | 70000 |
| 3 | Robert Lee | 40 | Finance | 75000 |
| 5 | Michael Roy | 35 | HR | 52000 |
| 6 | Alice Green | 27 | HR | 48000 |

15. Instruction: Retrieve the names and ages of employees whose age is
between 25 and 35.

Query:

sql

SELECT name, age FROM employees WHERE age BETWEEN 25


AND 35;

Explanation: This query retrieves employees whose age is between 25 and 35,
inclusive.

Output:

| name | age |
|-------------|-----|
| Jane Doe | 25 |
| Emily Davis | 28 |
| Michael Roy | 35 |

15 Java Programs and their outputs:

1. Instruction: Print "Hello World".

Program:
java

public class HelloWorld {


public static void main(String[] args) {
System.out.println("Hello World");
}
}

Explanation: This program prints "Hello World" to the console.

Output:

Hello World

2. Instruction: Add two numbers.

Program:

java

public class AddNumbers {


public static void main(String[] args) {
int a = 5, b = 10;
int sum = a + b;
System.out.println("Sum: " + sum);
}
}

Explanation: This program adds two numbers, a and b, and prints the sum.

Output:

Sum: 15

3. Instruction: Find the largest of two numbers.

Program:

java

public class LargestNumber {


public static void main(String[] args) {
int a = 10, b = 20;
if (a > b) {
System.out.println(a + " is the largest");
} else {
System.out.println(b + " is the largest");
}
}
}

Explanation: This program compares two numbers and prints the larger one.

Output:

20 is the largest

4. Instruction: Print numbers from 1 to 10.

Program:

java

public class PrintNumbers {


public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
System.out.println(i);
}
}
}

Explanation: This program prints the numbers from 1 to 10.

Output:

1
2
3
4
5
6
7
8
9
10

5. Instruction: Calculate the sum of two numbers.

Program:

java
public class Sum {
public static void main(String[] args) {
int a = 7, b = 8;
int sum = a + b;
System.out.println("Sum: " + sum);
}
}

Explanation: This program calculates and prints the sum of two numbers.

Output:

Sum: 15

6. Instruction: Reverse a string.

Program:

java
public class ReverseString {
public static void main(String[] args) {
String str = "Hello";
String reversed = new
StringBuilder(str).reverse().toString();
System.out.println("Reversed: " + reversed);
}
}

Explanation: This program reverses the string "Hello" and prints it.

Output:

Reversed: olleH

7. Instruction: Check if a number is even or odd.

Program:
java

public class EvenOdd {


public static void main(String[] args) {
int number = 10;
if (number % 2 == 0) {
System.out.println(number + " is even");
} else {
System.out.println(number + " is odd");
}
}
}

Explanation: This program checks if a number is even or odd and prints the result.

Output:

10 is even

8. Instruction: Find the factorial of a number.

Program:
java

public class Factorial {


public static void main(String[] args) {
int number = 5;
int result = 1;
for (int i = 1; i <= number; i++) {
result *= i;
}
System.out.println("Factorial: " + result);
}
}

Explanation: This program calculates the factorial of a number and prints it.

Output:

Factorial: 120

9. Instruction: Find the sum of elements in an array.

Program:
java

public class ArraySum {


public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
int sum = 0;
for (int num : numbers) {
sum += num;
}
System.out.println("Sum of elements: " + sum);
}
}

Explanation: This program calculates the sum of elements in an array.

Output:

Sum of elements: 15

10. Instruction: Swap two numbers.

Program:
java

public class SwapNumbers {


public static void main(String[] args) {
int a = 10, b = 20;
System.out.println("Before swap: a = " + a + ",
b = " + b);
int temp = a;
a = b;
b = temp;
System.out.println("After swap: a = " + a + ",
b = " + b);
}
}

Explanation: This program swaps two numbers using a temporary variable.

Output:

Before swap: a = 10, b = 20


After swap: a = 20, b = 10

11. Instruction: Check if a number is positive, negative, or zero.

Program:

java
public class NumberSign {
public static void main(String[] args) {
int number = -5;
if (number > 0) {
System.out.println(number + " is
positive");
} else if (number < 0) {
System.out.println(number + " is
negative");
} else {
System.out.println("The number is zero");
}
}
}

Explanation: This program checks if a number is positive, negative, or zero.

Output:

-5 is negative

12. Instruction: Print the multiplication table of a number.

Program:
java

public class MultiplicationTable {


public static void main(String[] args) {
int number = 7;
for (int i = 1; i <= 10; i++) {
System.out.println(number + " * " + i + " =
" + (number * i));
}
}
}

Explanation: This program prints the multiplication table for a number.

Output:

7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
...
7 * 10 = 70

13. Instruction: Find the largest number in an array.

Program:
Java

public class LargestInArray {


public static void main(String[] args) {
int[] numbers = {1, 3, 7, 2, 5};
int largest = numbers[0];
for (int num : numbers) {
if (num > largest) {
largest = num;
}
}
System.out.println("Largest number: " +
largest);
}
}

Explanation: This program finds the largest number in an array.

Output:

Largest number: 7

14. Instruction: Check if a number is a prime number.

Program:
java

public class PrimeNumber {


public static void main(String[] args) {
int number = 7;
boolean isPrime = true;
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.println(number + " is prime");
} else {
System.out.println(number + " is not
prime");
}
}
}

Explanation: This program checks if a number is prime.

Output:

7 is prime

15. Instruction: Calculate the area of a circle.

Program:
java

public class CircleArea {


public static void main(String[] args) {
double radius = 5;
double area = Math.PI * radius * radius;
System.out.println("Area of the circle: " +
area);
}
}

Explanation: This program calculates the area of a circle using the formula: π *
r².

Output:

Area of the circle: 78.53981633974483


Bibliography

1. W3Schools
W3Schools was used as a reference for learning and understanding
the basics of MySQL and Java.
o MySQL Tutorial: https://www.w3schools.com/sql/
o Java Tutorial: https://www.w3schools.com/java/

2. GeeksforGeeks
GeeksforGeeks provided additional examples and explanations for
both MySQL queries and Java programs.
o MySQL: https://www.geeksforgeeks.org/mysql-tutorial/
o Java: https://www.geeksforgeeks.org/java/

3. Java Documentation - Oracle


The official Java documentation from Oracle helped in
understanding key Java concepts.
o Java Documentation: https://docs.oracle.com/en/java/

These resources helped to gather the necessary knowledge for


completing this project.
Acknowledgment

I would like to express my sincere gratitude to all those who


have contributed to the successful completion of this project.
First and foremost, I would like to thank Mr. Manoj Bhoj, my
subject teacher, for his continuous guidance, support, and
valuable insights throughout the project. His encouragement and
feedback helped me stay focused and complete the project with
ease.
I would also like to acknowledge my parents and friends for
their unwavering support and motivation. Their encouragement
has been instrumental in completing this project successfully.
Finally, I appreciate the resources provided by W3Schools,
GeeksforGeeks, and other online platforms that helped me gain
a deeper understanding of the concepts related to MySQL and
Java programming.
Thank you all for your assistance and support.
Narendra Giri
Class: 12th "Commerce"
Conclusion

In this project, I have explored and implemented fundamental


concepts of MySQL and Java programming. The project helped
me understand how to write and execute basic SQL queries, as
well as create simple Java programs that solve everyday
problems. Through this work, I gained hands-on experience with
database management and programming logic.
Overall, this project enhanced my skills in both MySQL and
Java, and I believe it will be useful for future learning and
development in the field of Information Technology.
Narendra Giri
Class: 12th "Commerce"
Certificate

This is to certify that Narendra Giri student of class 12th


“commerce” has successfully completed the project work of
"Information Technology Code 802"under the guidance of
Mr. Manoj Bhoj, Subject Teacher. This project demonstrates
the understanding and application of fundamental concepts in
MySQL and Java programming.
Date:
Instructor: Mr. Manoj Bhoj

Internal Examiner's Signature: __________________

External Examiner's Signature: __________________

Principal's Signature: __________________

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy