Ajp Exp 18 Op
Ajp Exp 18 Op
Ajp Exp 18 Op
Program Code:
1. Write a Program to create a Student Table in database and insert a record in a Student table.
import java.sql.*;
import java.sql.*;
class CreateEmployeeTable {
public static void main(String[] args) {
try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:4008/Student", "root", " root ");
Statement st = con.createStatement()) {
String createTableSQL = "CREATE TABLE employee (emp_id INT PRIMARY KEY, emp_name
VARCHAR(100));";
st.execute(createTableSQL);
System.out.println("Created Table 'employee'");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
2. Develop a program to display the name and roll_no of students from “student table” having
percentage > 70.
import java.sql.*;
class DisplayStudents {
public static void main(String[] args) {
try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:4008/Student", "root", "root");
Statement st = con.createStatement()) {
String query = "SELECT Name, Roll_No FROM Student WHERE Percentage > 70;";
ResultSet rs = st.executeQuery(query);
} catch (SQLException e) {
e.printStackTrace();
}
}