FinalExam ICT
FinalExam ICT
12-ICT-
OLIVET
PART I. Manipulating data from Oracle Database using types of statements in JDBC.
1. Create a Student Information and Enrolled Subject Table in oracle database using types of
statement in JDBC.
TABLE 1.
public void createTable() throws SQLException {
String createString = "create table Student Info" +
"(S_ID integer NOT NULL," + "LRN integer NOT NULL," +
"First_Name varchar (40) NOT NULL," +
"Last_Name varchar (40) NOT NULL," +
"Gender varchar (20) NOT NULL," +
"Age integer NOT NULL," +
"Address varchar (20) NOT NULL," +
"Contact integer NOT NULL, ")";"
}
}
Try (Statement stu = con.createStatement()) {
stu.executeUpdate(createString);
} catch (SQLException e) {
StudentInformatio.printSQLException(e);
}
TABLE 2.
public void createTable() throws SQLException {
String createString = "create table Enrolled Subjects" +
"(LRN integer NOT NULL," + Subject_Code varchar(20) NOT NULL," +
"Subject_Name varchar (20) NOT NULL," +
"Instructor varchar (40) NOT NULL," +
"Schedule varchar(20) NOT NULL, ")";"
}
}
Try (Statement es = con.createStatement()) {
es.executeUpdate(createString);
} catch (SQLException e) {
EnrolledSubjects.printSQLException(e);
}
2. Insert data to Student Information and Enrolled Subject table using types of Statements in
JDBC. Insert five names of students and each students have three Enrolled Subjects which
are CS15, ATS6 and CS18-4
TABLE 1.
Import java.sql.*;
public static void main(String[] args){
//Execute query
System.out.println(“Inserting records into table..”);
String
sql = “INSERT INTO Student_Info VALUES (01, 107960090138, ‘Czion Jacob’,’Polecina’,
‘Male’, 18, ‘Pasong Kawayan’, 09203733275)”;
stmt.executeUpdate(sql);
sql = “INSERT INTO Student_Info VALUES (02, 13648090022, ‘Matthew ’,’Cabulong’,
‘Male’, 18, ‘Parksville’, 09777686170)”;
stmt.executeUpdate(sql);
sql = “INSERT INTO Student_Info VALUES (03, 125543120260, ‘Christel Bhea’,’Generalao’,
‘Female’, 19, ‘Gentri’, 09700329305)”;
stmt.executeUpdate(sql);
sql = “INSERT INTO Student_Info VALUES (04, 42481015136, ‘Pauline Mae’,’ Alicando’,
‘Female’, 18, ‘Lancaster’, 09668798276)”;
stmt.executeUpdate(sql);
sql = “INSERT INTO Student_Info VALUES (05, 107960120062, ‘Mark Gerlex’,’Oracion’,
‘Male’, 18, ‘Gentri’, 09773023024)”;
stmt.executeUpdate(sql);
TABLE 2.
Import java.sql.*;
public static void main(String[] args){
//Execute query
System.out.println(“Inserting records into table..”);
String
sql = “INSERT INTO Enrolled_Subjects VALUES (107960090138, ‘ ’, ‘ICT’, ‘Richard
Reforma’, ‘Monday’)”;
stmt.executeUpdate(sql);
sql = “INSERT INTO Enrolled_Subjects VALUES (13648090022, ‘ ’, ‘ICT’, ‘Richard
Reforma’, ‘Monday’)”;
stmt.executeUpdate(sql);
sql = “INSERT INTO Enrolled_Subjects VALUES (125543120260, ‘CS15’, ‘MIL’, ‘Christine
Biangco’, ‘Tuesday’)”;
stmt.executeUpdate(sql);
sql = “INSERT INTO Enrolled_Subjects VALUES (42481015136, ‘ATS6’, ‘Entrep’, ‘Raymart
Esguerra’, ‘Tuesday’)”;
stmt.executeUpdate(sql);
sql = “INSERT INTO Enrolled_Subjects VALUES (107960120062, ‘CS18-4’, ‘Christian
Values’, ‘Thursday’)”;
stmt.executeUpdate(sql);
Import java.sql.*;
static final String QUERY = “SELECT S_ID, LRN, First_Name, Last_Name, Gender, Age,
Address Contact FROM Student_Info”;
Import java.sql.*;
static final String QUERY = “SELECT S_ID, LRN, First_Name ||’ ‘||Last_Name AS Name,
Subject_Code, Subject_Name, Schedule FROM Student_Information, Enrolled_Subjects”;
5. Create a query to add enrolled subject ICT:4b Oracle Database in student no. 1 & 2.
TABLE 2 (UPDATE)
Import java.sql.*;
class InsertPrepared{
public static void main (String[] args){
try {
int i=stmt.executeUpdate();
System.out.println(i+”Recors inserted”);
con.close();
} catch (Exception e) {System.out.println(e);}
}
}