0% found this document useful (0 votes)
7 views4 pages

SQL and Java Programs

The document contains a collection of SQL queries and Java programs. The SQL section includes various commands for data manipulation and table management, while the Java section features programs demonstrating basic programming concepts such as loops, conditionals, and arithmetic operations. Overall, it serves as a reference for both SQL and Java programming practices.

Uploaded by

pandeyvinu0507
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)
7 views4 pages

SQL and Java Programs

The document contains a collection of SQL queries and Java programs. The SQL section includes various commands for data manipulation and table management, while the Java section features programs demonstrating basic programming concepts such as loops, conditionals, and arithmetic operations. Overall, it serves as a reference for both SQL and Java programming practices.

Uploaded by

pandeyvinu0507
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/ 4

SQL Queries and Java Programs

SQL Queries

1. SELECT * FROM students;

2. SELECT name FROM employees WHERE salary > 50000;

3. INSERT INTO customers (name, email) VALUES ('John Doe', '[email protected]');

4. UPDATE orders SET status = 'shipped' WHERE order_id = 102;

5. DELETE FROM logs WHERE log_date < '2024-01-01';

6. CREATE TABLE books (id INT PRIMARY KEY, title VARCHAR(100), author VARCHAR(100));

7. ALTER TABLE students ADD COLUMN grade VARCHAR(2);

8. DROP TABLE temp_data;

9. SELECT COUNT(*) FROM users WHERE active = true;

10. SELECT department, AVG(salary) FROM employees GROUP BY department;

11. SELECT * FROM sales WHERE sale_date BETWEEN '2024-01-01' AND '2024-06-30';

12. SELECT name FROM products WHERE name LIKE 'A%';

13. CREATE INDEX idx_name ON customers(name);

14. SELECT MAX(score) FROM exams;

15. SELECT e.name, d.dept_name FROM employees e JOIN departments d ON e.dept_id = d.id;

Java Programs

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

2.
public class Sum {
public static void main(String[] args) {
int a = 5, b = 10;
System.out.println("Sum: " + (a + b));
}
}
SQL Queries and Java Programs

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

4.
public class PrimeCheck {
public static void main(String[] args) {
int num = 7;
boolean isPrime = true;
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
System.out.println(num + " is prime: " + isPrime);
}
}

5.
public class Palindrome {
public static void main(String[] args) {
String str = "madam";
String rev = new StringBuilder(str).reverse().toString();
System.out.println("Palindrome: " + str.equals(rev));
}
}

6.
public class Fibonacci {
public static void main(String[] args) {
int n1 = 0, n2 = 1, n3;
System.out.print(n1 + " " + n2);
for (int i = 2; i < 10; ++i) {
n3 = n1 + n2;
System.out.print(" " + n3);
n1 = n2;
n2 = n3;
}
}
}

7.
public class ReverseNumber {
public static void main(String[] args) {
SQL Queries and Java Programs

int num = 1234, rev = 0;


while (num != 0) {
rev = rev * 10 + num % 10;
num /= 10;
}
System.out.println("Reversed: " + rev);
}
}

8.
public class EvenOdd {
public static void main(String[] args) {
int num = 4;
System.out.println(num + " is " + (num % 2 == 0 ? "Even" : "Odd"));
}
}

9.
public class Armstrong {
public static void main(String[] args) {
int num = 153, temp = num, sum = 0;
while (temp != 0) {
int digit = temp % 10;
sum += Math.pow(digit, 3);
temp /= 10;
}
System.out.println("Armstrong: " + (sum == num));
}
}

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

11.
public class Largest {
public static void main(String[] args) {
int a = 20, b = 30, c = 10;
int max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
System.out.println("Largest: " + max);
}
}

12.
public class Table {
SQL Queries and Java Programs

public static void main(String[] args) {


int num = 5;
for (int i = 1; i <= 10; i++) {
System.out.println(num + " x " + i + " = " + (num * i));
}
}
}

13.
public class SumOfDigits {
public static void main(String[] args) {
int num = 123, sum = 0;
while (num != 0) {
sum += num % 10;
num /= 10;
}
System.out.println("Sum of digits: " + sum);
}
}

14.
public class Pattern {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}

15.
public class GCD {
public static void main(String[] args) {
int a = 54, b = 24;
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
System.out.println("GCD: " + a);
}
}

You might also like