0% found this document useful (0 votes)
21 views3 pages

FinalExam ICT

1. The document details steps to create and populate tables in an Oracle database using JDBC statements. It creates Student Information and Enrolled Subject tables, inserts data for 5 students and their subjects, and writes queries to display the data. 2. Queries are written to display student information from the Student Information table and a joined query to display student ID, name, subject code, name and schedule. 3. An update statement is provided to add an additional enrolled subject, ICT:4b Oracle Database, to students 1 and 2.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

FinalExam ICT

1. The document details steps to create and populate tables in an Oracle database using JDBC statements. It creates Student Information and Enrolled Subject tables, inserts data for 5 students and their subjects, and writes queries to display the data. 2. Queries are written to display student information from the Student Information table and a joined query to display student ID, name, subject code, name and schedule. 3. An update statement is provided to add an additional enrolled subject, ICT:4b Oracle Database, to students 1 and 2.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ALICANDO, PAULINE MAE B.

12-ICT-
OLIVET

SIR RICHARD C. REFORMA FINAL


EXAMINATION

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);

System.out.println(“Records successfully inserted into table..”);


} catch (SQLException e) {
e.printStackTrace();
}

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);

System.out.println(“Records successfully inserted into table..”);


} catch (SQLException e) {
e.printStackTrace();
}

3. Create to display Student Information using types of Statements in JDBC.

Import java.sql.*;
static final String QUERY = “SELECT S_ID, LRN, First_Name, Last_Name, Gender, Age,
Address Contact FROM Student_Info”;

public static void main (String[] args) {


Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(QUERY);
}{
While(rs.nect()) {
//Display
Sytem.out.println(“S_ID: ” + rs.getInteger(“S_ID”));
Sytem.out.println(“, LRN: ” + rs.getInteger(“LRN”));
Sytem.out.println(“, First_Name: ” + rs.getString(“First_Name”));
Sytem.out.println(“, Last_Name: ” + rs.getString(“Last_Name”));
Sytem.out.println(“, Gender: ” + rs.getString(“Gender”));
Sytem.out.println(“, Age: ” + rs.getInteger(“Age”));
Sytem.out.println(“, Address: ” + rs.getString(“Address”));
Sytem.out.println(“, Contact: ” + rs.getInteger(“Contact”));
}
} catch (SQLException e) {
e.printStackTrace();
}

4. Create a query to display S_ID, LRN, (First_Name, Last_Name), as Name, Subject_Code,


Subject_Name, and Schedule

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”;

public static void main (String[] args) {


Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(QUERY);
}{
While(rs.nect()) {
//Display
Sytem.out.println(“S_ID, LRN, First_Name, Last_Name: ” + rs.getString +
rs.getInteger(“Name”));
Sytem.out.println(“, Subject_Code: ” + rs.getInteger(“SCode”));
Sytem.out.println(“, Subject_Name: ” + rs.getString(“SName”));
Sytem.out.println(“, Ss: ” + rs.getString(“Address”));
}
} catch (SQLException e) {
e.printStackTrace();
}

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 {

PreparedStatement stmt=con.prepareStatement(“Insert into Enrolled_Subjects values(?,?)”);


stmt.setInt(?,?);
stmt.setString(?,?);

int i=stmt.executeUpdate();
System.out.println(i+”Recors inserted”);

con.close();
} catch (Exception e) {System.out.println(e);}
}
}

You might also like