Sunteți pe pagina 1din 4

JDBC–Exercise

Table name: java_employees

Table structure:

Connection details
JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver"
DB_URL = "jdbc:oracle:thin:@192.168.1.12:1521:edukdev"
USER_NAME = "HOT_ACADEMY" ; PASSWORD = "ha11marks"

#1 Program
Create a Java program and access the table “Java_employees” and display all the results in the below
format

OUTPUT
ID:195; FNAME:David; LNAME:Lee; EMAIL: DLEE
…..

Query : select * from java_employees

#2 Program
Create a Java program and access the table “Java_employees” and load the email address to the Array[]
and display the results from the Array.

OUTPUT
Selvakumar.balraj@gmail.com

Query : select email from java_employees

#3 Program:
1. Create a Bean for all the columns in the Java_employees table.
2. Write a Java program to read a value for Department Id
3. If the department id is not number then raise error else proceed with below
4. Fetch all the records FROM THE TABLE using PreparedStatement that matches the department
Id and load the DATA TO THE BEAN.
5. Print all the results from the bean in below format where the salary less than 5000
6. If there is no result then raise a message “Department not matched with the employee…”

OUTPUT
ID:195; FNAME:David; LNAME:Lee; EMAIL: DLEE……..
…..
Query : select * from Java_employees where DEPARTMENT_ID = ….
JDBC–Exercise

#4 Program:
1. Read the 2 numbers and process_type as string from the keyboard
2. Process_type should be ADD/MULTIPLY/DIVIDE/MOD else raise error
3. Number should be an integer
4. If the input data is incorrect then need to raise the error.
5. If the input data is correct then, pass the value to the below procedure and print the output.

OUTPUT
Procedure details: JAVA_ACADEMY.PROCESS_REQUEST_PRC ( p_number1 IN NUMBER ,
p_number2 IN NUMBER ,
p_type IN VARCHAR,
l_results OUT NUMBER
);

#5 Program:
1. Read the employee ID, if not an number then raise error - “Please enter valid number”;
2. Pass the employee id to the procedure and print the details of the employee

OUTPUT
ID:195;
FNAME:David;
LNAME:Lee;
EMAIL: DLEE
…..
Procedure details: JAVA_ACADEMY.GET_EMPLOYEE_INFO_PRC (
p_employee_id IN NUMBER ,
lc_employee_info OUT SYS_REFCURSOR
);
 Cursor values
 employee_id
 first_name
 last_name
 email
 phone_number
 hire_date
 job_id
 salary
 commission_pct
 manager_id
 department_id

#6 Program:
Read the below value and validate each field and raise error if the data not valid, if data is valid then
insert the details to the table using the prepared statement.

EMPLOYEE_ID NUMBER(6),
FIRST_NAME VARCHAR2(20 BYTE),
LAST_NAME VARCHAR2(25 BYTE) NOT NULL,
JDBC–Exercise

EMAIL VARCHAR2(25 BYTE) NOT NULL,


PHONE_NUMBER VARCHAR2(20 BYTE),
HIRE_DATE DATE NOT NULL, -- MM/DD/YYYY2
JOB_ID VARCHAR2(10 BYTE) NOT NULL,
SALARY NUMBER(8,2),
COMMISSION_PCT NUMBER(2,2),
MANAGER_ID NUMBER(6),
DEPARTMENT_ID NUMBER(4)

Query : Insert into JAVA_EMPLOYEES


(EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID,
SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID)
Values (?....);

#7 Program:
Create a new table with the starts with JAVA_MOVIE_GRP_[YOUR NAME_4CHAR] having the below
structure.

GROUP_ID NUMBER(10),
GROUP_NAME VARCHAR2(40),

Move the below data to the HASP_MAP and add the data to the table using a java program
GROUP_ID GROUP_NAME
1000 ACTION_MOVIE
1001 COMEDY_MOVIE
1002 FAMILY_MOVIE
1003 ROMANCE
1004 CHILDREN
1005 HORROR
1006 DOCUMENTARY
1007 SUSPENSE/THRILLER

#8 Program:
Create a new table which the starts with JAVA_MOVIE_[YOUR NAME_4CHAR] having the below
structure.

MOVIE_ID NUMBER(6),
MOVIE_NAME VARCHAR2(40 BYTE),
ACTOR_NAME VARCHAR2(40 BYTE),
GROUP_ID NUMBER (10),

Read 10 records and Add to the above table.


Before storing to the table, check whether the given GROUP_ID exists in the GROUP table, if not exists
then raise an error else insert INTO the table.

#9 Program:
Create a Java program
1. To read the data from the table “JAVA_MOVIE_[YOUR NAME_4CHAR]” and
“JAVA_MOVIE_GRP_[YOUR NAME_4CHAR]” and store the values to 2 bean separately (A) and (B)
JDBC–Exercise

2. Create another bean(C) with the below column copy the data to the bean (C) from bean (A)
and (B)
a. MOVIE_ID
b. MOVIE_NAME
c. ACTOR_NAME
d. GROUP_NAME

3. Print the value from the bean (C)

NOTE: ** use separate method for each action.

#10 Program:
Create a new table with the starts with MOVIE_COPIED_[YOUR NAME_4CHAR] having the below
structure.

MOVIE_ID NUMBER(6),
MOVIE_NAME VARCHAR2(40 BYTE),
ACTOR_NAME VARCHAR2(40 BYTE),
GROUP_NAME VARCHAR2(40 BYTE),

Copy the record from the table “JAVA_MOVIE_[YOUR NAME_4CHAR]” and “JAVA_MOVIE_GRP_[YOUR
NAME_4CHAR]” to the table MOVIE_COPIED_[YOUR NAME_4CHAR ] and print the result from the
MOVIE_COPIED_[YOUR NAME_4CHAR] table.

NOTE: ** use separate method for each action.

#11 Program:
Create a java program to accept a department_id. Department_id should be a number or null, if valid
value then call the below procedure and display the results. If the value passed then it return the cursor
for the specific department or else it will return a cursor that contains all the rows from the department
table. Print the values for both the scenarios. Use separate method for each scenarios. Move the data to
a bean and print the result.

PROCEDURE JAVA_ACADEMY.get_department_data_prc(
p_department_id IN NUMBER ,
lc_department_info OUT SYS_REFCURSOR
)

Column from the cursor


department_id
department_name
manager_id
location_id

S-ar putea să vă placă și