Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

18PE04/18FE04/18SE04 – Advanced Java Programming

Module 1 - Lab Exercise on JDBC

1. Consider the following “Nobel Prize” database table:


Name Year Subject

Rabindranath Tagore 1913 Literature


C. V. Raman 1930 Physics
Mother Teresa 1979 Peace
Amartya Sen 1998 Economic studies
Kailash Satyarthi 2014 Peace
Develop a Java program to connect with database and retrieve following details:
• Write a Java code to insert records by reading input from user.
• Display all the details which are stored in Nobel Prize table.
• Display the details of the Nobel Prize winners who got for the subject Peace.
• Delete the NobelPrize winners who got NobelPrize before 1930.

2. Given the following table containing information about employees of an organization,


develop a small java application, using JDBC, which displays a menu for the user consisting
of following options: (Use Prepared Statement for Executing Queries)
1. Add Record
2. Modify Record
3. Delete Record
4. Display one Record
5. Display All
6. Exit
Use Scanner class to accept input from the user.
Employee_table

Add Record :
When the user input is 1, the user should be asked to enter the following details one by
one (again using Scanner).
Employee ID
Employee’s First Name
Employee’s last Name
Join Date
Department
18PE04/18FE04/18SE04 – Advanced Java Programming

Designation
Basic Salary
The data entered by the user should be stored in database table
Modify Record:
If the user selects option 2, Modify Record, the user should be asked to enter the
employee no. whose data he needs to modify. When the user enters the employee no.,
the application should display the employee’s details like employee no., designation,
department and basic salary. If the employee no. is not present, it should display
appropriate error message. The user should be able to change only the Designation and
Basic Salary.
Delete Record:
When the user selects option 3, Delete Record, the application should ask him to enter
the employee no. and if the employee no. does not exist, it should display appropriate
error message. If the employee no. exists, the record should be deleted.
Display One Record
When the user selects option 4, Display One Record, the application should ask him to
enter the employee no. and if the employee no. does not exist, it should display
appropriate error message. If the employee no. exists, it should display all the details of
this employee.
Display all Records
When the user selects option 5, Display all Records, the application should display all the
records.
Exit
When the user wants to stop using this application, he will select option 6 and he should
be allowed to exit from this system. It should display a message on the system “Thank you
for using this application”

3. Consider the following “Book” table:


Title Author Publication Price in Rs.

Java: The complete reference Herbert Schildt Prentice Hall 659.00


C Programming in Linux David Haskins John Wiley & Sons 788.00
HeadFirst java script Nickel Morison O’ Reilly 500.00
Develop a Java program to connect with database and retrieve following details:
1) Add a new book ‘HTML, CSS & JavaScript’ by Laura Lemay, Prentice Hall, Rs.
250.00 using Prepared Statement.
2) Display all the details which are stored in Books table.
3) Create a Procedure to increase the price of books by Rs.200.
4) Create a Procedure to add new record into table.
5) Execute procedures using Callable Statement.

You might also like