Java Database Connectivity (JDBC) Programming Questions
Q1. JDBC Connection and Table Creation
a) Write a Java program to load JDBC driver and establish a database connection.
b) Create a table Employee(EID INT PRIMARY KEY, Name VARCHAR(30), Salary
INT).
c) Add proper exception handling for connection failure.
Q2. Insert Records using Statement
a) Write code to insert 5 records into Employee table using Statement.
b) Modify the program to accept input from user and insert dynamically.
c) Display number of rows affected for each insert.
Q3. Data Retrieval using ResultSet
a) Write a program to retrieve employees with salary greater than 50000.
b) Display employee name and salary.
c) Count and print total number of records retrieved.
Q4. Update and Delete Operations
a) Write code to update salary of employee with EID = 101.
b) Delete employees whose salary is less than 20000.
c) Print number of rows affected for both operations.
Q5. ResultSet Navigation
a) Write a program to display all records from Employee table.
b) Use appropriate ResultSet methods to retrieve column values.
c) Show what happens if next() is not used before accessing data.
Q6. PreparedStatement for Insert
a) Rewrite insertion of employee records using PreparedStatement.
b) Use parameterized query with placeholders (?).
c) Execute the same PreparedStatement multiple times with different values.
Q7. Parameterized Query Execution
a) Write a PreparedStatement query to select employees with salary greater than a given value.
b) Execute it for three different salary values.
c) Display results for each execution separately.
Q8. Method-Based JDBC Implementation
a) Write a method addEmployee(Connection conn, int id, String name, int
salary) using PreparedStatement.
b) Call this method multiple times from main().
c) Ensure connection is reused efficiently.
Q9. Exception Handling in JDBC
a) Write a program that attempts to insert duplicate primary key values.
b) Catch and handle the SQLException.
c) Display a user-friendly error message.
Q10. Integrated JDBC Program
a) Write a complete program to create table Student(ID, Name, Marks).
b) Insert at least 5 records using PreparedStatement.
c) Retrieve and display students with marks greater than 60.
d) Use Statement, PreparedStatement, and ResultSet appropriately.