Prac 18
Prac 18
Write a Program to create a Student Table in database and insert a record in a Student
table.
Code:
import java.sql.*;
public class Prac_18_1 {
public Prac_18_1() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/Pratik", "root", "");
stmt.executeUpdate(table);
System.out.println("Student table created successfully.");
String insert = "insert into Student (name, age, grade) values ('Pratik', 19, 'A')";
stmt.executeUpdate(insert);
System.out.println("Record inserted successfully.");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new Prac_18_1();
}
}
Output:
2. Develop a program to create employee table in database having two columns “emp_id”
and “emp_name”
Code:
import java.sql.*;
public class Prac_18_2 {
public Prac_18_2() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
stmt.executeUpdate(table);
System.out.println("Employee table created successfully.");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new Prac_18_2();
}
}
Output:
3. Develop a program to display the name and roll_no of students from “student table”
having percentage > 70
Code:
import java.sql.*;
public class Prac_18_3 {
public Prac_18_3() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/Pratik", "root", "");