MCA (Revised) / BCA (Revised)
Term-End Examination
June, 2022
MCS-024 : OBJECT ORIENTED TECHNOLOGIES AND
JAVA PROGRAMMING
```
java Program
import java.sql.*;
public class JdbcExample {
public static void main(String[] args) {
// JDBC connection parameters
String url = "jdbc:mysql://localhost:3306/mydatabase";
String username = "your_username";
String password = "your_password";
// SQL query
String sql = "SELECT BOOK_AUTH, BOOK_PRICE FROM BOOK WHERE BOOK_ISBN = 500123";
try {
// Create a connection to the database
Connection connection = DriverManager.getConnection(url, username, password);
// Create a statement object
Statement statement = connection.createStatement();
// Execute the SQL query
ResultSet resultSet = statement.executeQuery(sql);
// Process the query results
if (resultSet.next()) {
String bookAuth = resultSet.getString("BOOK_AUTH");
double bookPrice = resultSet.getDouble("BOOK_PRICE");
System.out.println("Book Author: " + bookAuth);
System.out.println("Book Price: " + bookPrice);
} else {
System.out.println("No book found with ISBN = 500123");
}
// Close the resources
resultSet.close();
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
```
```
java Program
class Teacher {
private String name;
private int age;
private String subject;
public Teacher(String name, int age, String subject) {
this.name = name;
this.age = age;
this.subject = subject;
}
public void displayInformation() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Subject: " + subject);
}
}
class PGT extends Teacher {
private String level;
public PGT(String name, int age, String subject, String level) {
super(name, age, subject);
this.level = level;
}
@Override
public void displayInformation() {
super.displayInformation();
System.out.println("Level: " + level);
}
}
class TGT extends Teacher {
private String qualification;
public TGT(String name, int age, String subject, String qualification) {
super(name, age, subject);
this.qualification = qualification;
}
@Override
public void displayInformation() {
super.displayInformation();
System.out.println("Qualification: " + qualification);
}
}
class PRT extends Teacher {
private String primarySection;
public PRT(String name, int age, String subject, String primarySection) {
super(name, age, subject);
this.primarySection = primarySection;
}
@Override
public void displayInformation() {
super.displayInformation();
System.out.println("Primary Section: " + primarySection);
}
}
public class TeacherExample {
public static void main(String[] args) {
PGT pgtTeacher = new PGT("John Doe", 35, "Physics", "Senior");
TGT tgtTeacher = new TGT("Jane Smith", 32, "Mathematics", "Master's");
PRT prtTeacher = new PRT("Alice Johnson", 28, "English", "Grade 1");
System.out.println("PGT Teacher Information:");
pgtTeacher.displayInformation();
System.out.println("\nTGT Teacher Information:");
tgtTeacher.displayInformation();
System.out.println("\nPRT Teacher Information:");
prtTeacher.displayInformation();
}
}
```
0 Comments
Please do not enter any spam link in the comment box.