0% found this document useful (0 votes)
59 views11 pages

Java-II Programming Question Bank

The document contains a question bank for a Computer Programming using Java-II exam, including multiple choice questions (MCQ) on topics like file input/output, JDBC, and database concepts. Some example questions are on reading/writing files, the components of JDBC, loading a database driver, and calling stored procedures. The note indicates this bank is only for reference and the actual exam questions may differ.

Uploaded by

malav piya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views11 pages

Java-II Programming Question Bank

The document contains a question bank for a Computer Programming using Java-II exam, including multiple choice questions (MCQ) on topics like file input/output, JDBC, and database concepts. Some example questions are on reading/writing files, the components of JDBC, loading a database driver, and calling stored procedures. The note indicates this bank is only for reference and the actual exam questions may differ.

Uploaded by

malav piya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

L.J Institute of Engineering and Technology, Ahmedabad.

Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)


Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
308 8 Which of the following are true? B 1 i only ii only i and iii none of the
i) The InputStream and OutputStream classes are byte-oriented. mention
Ii) The ObjectInputStream and ObjectOutputStream do not
support serialized object input and output.
Ii) The Reader and Writer classes are character-oriented.
iV) The Reader and Writer classes are the preferred solution to
serialized object output.

309 8 What is the output of the following code? C 1 is Thi is Thi


import java.io.*;
import java.lang.String;
class test {
public static void main(String[] args) throws IOException {
// Object of RandomAccessFile
RandomAccessFile raf = new
RandomAccessFile("input.txt","r");
// Suppose, the input.txt file contains the following text
// This is a line of text inside the file.
// array to store the content of the file
byte[] bytes = new byte[12];

// offset is 8 and length is 3


raf.read(bytes, 8, 3);
raf.close();
System.out.println(new String(bytes)); } }

310 8 Write a JAVA program to read student.txt file and display the 4
content.
311 8 Write a program to read the content of a file into a character 4
array and write it into another file. Get names of the files from
command line.
312 8 Write a java program to search the file named the word entered 5
as a filename from command line; if it exists in the system then
program should print the content of a file on console.

313 8 Write a java program that read employee details and store into 4
emp.txt text file using file handling.
314 8 Write a program that counts number of characters, words, and 5
lines ina text file.
315 8 Create a class called Student. Write a student manager program 5
to manipulate the student information from files by using the
BufferedReader and BufferedWriter.
316 8 Write a java program to search the file named the word entered 5
as a filename from commandline: If it existsin the system the
program should print the contemts of the file on console
317 8 Write a Java program to copy content of file1.txt to file2.txt 4
using Java file handling
318 8 Write an application that reads a file and counts the number of 5
occurrences of digit 5. Supply the file name as a command-line
argument
319 8 Write a program to replace all “word1” by “word2” to a file 5
without using temporary file and display the no. of replacement.

320 8 Write a program to count the total no. of chars, words, lines, 5
alphabets, digits, white spaces in a given file.
321 8 Write a program to display the bytes of a file in reverse 4
sequence. Provide the name of the file as a command line
argument.
322 8 Write a program to sort the one file numbers to another.for 5
example one file contain the unsorted number separated by line
and write the another filr with sorted number.
323 8 Write a java program which read numbers from number.txt file 4
and store even number to even.txt and odd number into odd.txt
file.
324 9 What are the major components of the JDBC? A 1 DriverManager, DriverManager, DriverManager, DriverManager,
Driver, Driver, Statement, and Connection,
Connection, Connection, and ResultSet Statement, and
Statement, and Statement ResultSet
ResultSet
325 9 Select the packages in which JDBC classes are defined? D 1 jdbc and rdb and javax.rdb jdbc and sql and javax.sql
javax.jdbc java.jdbc.sql
Page 35 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
326 9 Thin driver is also known as? D 1 Type 3 Driver Type 1 Driver Type 2 Driver Type 4 Driver
327 9 What is the correct sequence to create a database connection? A 1 i, iii, ii, v, iv, vii, vi, i, ii, iii, v, iv, vii, ii, i, iii, iv, viii, vii, i, iii, ii, iv, v, vi, vii,
i. Import JDBC packages. viii viii, vi v, vi viii
ii. Open a connection to the database.
iii. Load and register the JDBC driver.
iv. Execute the statement object and return a query resultset.
v. Create a statement object to perform a query.
vi. Close the resultset and statement objects.
vii. Process the resultset.

328 9 Which of the following method is used to perform DML C 1 executeResult() executeQuery() executeUpdate() execute()
statements in JDBC?
329 9 Which of the following method is static and synchronized in JDBC C 1 prepareCall() executeUpdate() getConnection() executeQuery()
API?
330 9 Which methods are required to load a database driver in JDBC? D 1 getConnection() registerDriver() forName() Both b and c

331 9 Parameterized queries can be executed by? B 1 ParameterizedStat PreparedStateme CallableStatement All kinds of
ement nt and Statements
Parameterized
Statement
332 9 Which of the following is not a valid statement in JDBC? C 1 Statement PreparedStateme QueryStatement CallableStatement
nt
333 9 Stored procedure can be called by using the ? A 1 CallableStatement Statement CalledStatement PreparedStateme
nt
334 9 What should be the correct order to close the database D 1 Connection, ResultSet, Statements, ResultSet,
resource?What should be the correct order to close the Statements, and Connection, and ResultSet, and Statements, and
database resource? then ResultSet then Statements then Connection then Connection
335 9 Which of the following driver is the fastest one? D 1 JDBC-ODBC Native API Partly Network Protocol JDBC Net Pure
Bridge Driver Java Driver Driver Java Driver

336 9 Which method is used to establish the connection with the D 1 public static void public static void public static public static
specified url in a Driver Manager class? registerDriver(Driv deregisterDriver(D Connection Connection
er driver) river driver) getConnection(Str getConnection(Str
ing url) ing url,String
userName,String
password)
337 9 Which method is used for an SQL statement that is executed A 1 prepareStatement prepareCall createStatement None of the above
frequently?
338 9 JDBC stands for? A 1 Java database Java database java Data and java database
connectivity connection Bios Connectivity communication

339 9 Which driver converts JDBC calls directly into the vendor-specific C 1 Native - API driver Network Protocol Thin driver Both B & C
database protocol? driver
340 9 What is the output of the following Java code that uses D 1 The code will The code will The code will The names of all
Statement to execute a SQL query? throw an throw a throw a customers in the
import java.sql.*; SQLException ClassNotFoundExc NullPointerExcepti "customers" table
because the SQL eption because on because the will be printed to
public class Main { query is invalid. the MySQL JDBC ResultSet is not the console.
public static void main(String[] args) throws SQLException { driver is not initialized.
Connection conn = found.
DriverManager.getConnection("jdbc:mysql://localhost:3306/myd
atabase", "root", "password");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM
customers");
while (rs.next()) {
System.out.println(rs.getString("name"));
}
conn.close();
}
}

Page 36 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
341 9 What is the output of the following Java code that uses A 1 . The names of all The code will The code will The code will
PreparedStatement to execute a SQL query with a parameter? customers in the throw an throw a throw a
import java.sql.*; "customers" table SQLException ClassNotFoundExc NullPointerExcepti
public class Main { whose country is because the SQL eption because on because the
public static void main(String[] args) throws SQLException { "USA" will be query is invalid. the MySQL JDBC ResultSet is not
Connection conn = printed to the driver is not initialized.
DriverManager.getConnection("jdbc:mysql://localhost:3306/myd console. found.
atabase", "root", "password");
String sql = "SELECT * FROM customers WHERE country = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "USA");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("name")); }
conn.close(); } }

342 9 What is the output of the following Java code that uses B 1 The code will The code will The code will The value of the
CallableStatement to execute a stored procedure? throw an throw an Missing throw a "result" column
import java.sql.*; SQLException Parameter ClassNotFoundExc for the "John"
public class Main { because the Exception eption because input parameters
public static void main(String[] args) throws SQLException { stored procedure because the the MySQL JDBC will be printed to
Connection conn = is not found. parameters are driver is not the console.
DriverManager.getConnection("jdbc:mysql://localhost:3306/myd missing found.
atabase", "root", "password");
CallableStatement cstmt = conn.prepareCall("{call
myprocedure(?, ?)}");
cstmt.setString(1, "John");
boolean hasResults = cstmt.execute();
if (hasResults) {
ResultSet rs = cstmt.getResultSet();
while (rs.next()) {
System.out.println(rs.getString("result")); } }
conn.close(); } }
343 9 What is the output of the following Java code that uses A 1 One row with the The code will The code will The code will
PreparedStatement to execute an insert SQL query with multiple specified values throw an throw a throw a
parameters? will be inserted SQLException ClassNotFoundExc NullPointerExcepti
import java.sql.*;
into the because the SQL eption because on because the
public class Main {
public static void main(String[] args) throws SQLException { "customers" table query is invalid. the MySQL JDBC ResultSet is not
Connection conn = and the number driver is not initialized.
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase" of rows inserted found.
, "root", "password"); will be printed to
String sql = "INSERT INTO customers (name, address, city, country) the console.
VALUES (?, ?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "John Doe");
pstmt.setString(2, "123 Main St");
pstmt.setString(3, "New York");
pstmt.setString(4, "USA");
int rowsInserted = pstmt.executeUpdate();
System.out.println(rowsInserted + " rows inserted");
conn.close(); } }
Assume that the "customers" table has columns "name", "address",
"city", and "country".

Page 37 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
344 9 What is the output of the following Java code that uses A 1 The value of the The code will The code will The code will
CallableStatement to execute a stored procedure with OUT "result" OUT throw an throw a throw a
parameters? parameter for the SQLException ClassNotFoundExc NullPointerExcepti
import java.sql.*; "John Doe" input because the eption because on because the
public class Main { parameters will stored procedure the MySQL JDBC ResultSet is not
public static void main(String[] args) throws SQLException { be printed to the is not found. driver is not initialized.
Connection conn =
console. found.
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata
base", "root", "password");
CallableStatement cstmt = conn.prepareCall("{call myprocedure(?,
?, ?)}");
cstmt.setString(1, "John");
cstmt.setString(2, "Doe");
cstmt.registerOutParameter(3, Types.INTEGER);
cstmt.execute();
System.out.println(cstmt.getInt(3));
conn.close(); } }
Assume that the "myprocedure" stored procedure takes two IN
parameters "firstname" and "lastname" and one OUT parameter
"result" of type INTEGER.
345 9 Which of the following statements is true about D 1 It is used for It is used for It is used for It is used for
PreparedStatement in Java? executing executing static executing stored executing both
dynamic SQL SQL statements. procedures. static and
statements. dynamic SQL
statements.
346 9 Which of the following is true about CallableStatement in Java? C 1 It is used for It is used for It is used for It is used for
executing static executing executing stored executing both
SQL statements. dynamic SQL procedures. static and
statements. dynamic SQL
statements.
347 9 Which of the following is an advantage of using B 1 Better Increased Ability to execute All of the above
PreparedStatement over Statement in Java? performance for security against DDL statements
complex queries SQL injection
attacks
348 9 _______ method can be used for any SQL statements(Select and C 1 executeQuery executeUpdate execute All of the above
Update both).
349 9 Which of the following is advantage of using PreparedStatement C 1 Slow Performance Encourage SQL Prevents SQL More Memory
in Java? Injection Injection Usage
350 9 What will be the output of the following? C 1 jdbc MySQL MySQL root
[Assume all the methods and necessary code is written there] Connector/J

DatabaseMetaData dbmd = con.getMetaData();


System.out.println(dbmd.getDatabaseProductName());
351 9 Which statement is the correct one for MySQL jdbc connection? D 1 getConnection(“jd getconnection(“m getConnection(“jd getConnection(“jd
bc.mysql.localhost ysql.jdbc.localhost bc:mysql://localh bc:mysql://localh
://3306/dbName” ://3306/dbName” ost:3306/dbName ost:3306/dbName
, “root”, “”); , “root”, “”); ”, “root”, “”); ”, “root”, “”);

352 9 Which line contains an ERROR? [Assume all the necessary lines D 1 1,2,5 2,5,6 2,4,5,6 2, 6
before line 1 is already there in the code]
1. String sql = “insert into table values(?,?,?)”;
2. PreparedStatement pst = con.preparedStatement(sql);
3. pst.setInt(1,1324);
4. pst.setString(2, “1324”);
5. pst.setString(3, “1324”);
6. pst.executeQuery();

353 9 Which lines are correct? [Assume all the necessary lines before B 1 1,3,4,5,6 1,2,3,4,5,6 2,3,4,5,6 4,5,6
line 1 is already there in the code & table have 4 columns –
facId(int), facName(String), salary(float), number(String)]
1. String sql = "insert into faculty (facName, salary, number )
values(?,?,?)";
2. PreparedStatement pst = con.prepareCall(sql);
3. pst.setString(1, "JKJKJKJKJKJ");
4. pst.setFloat(2, 789);
5. pst.setString(3, "888");
6. pst.execute();

Page 38 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
354 9 What is the correct syntax to store data of .java file to database. C 1 pst.getCharacterSt pst.getByteStream pst.setCharacterSt pst.setByteStream
Consider the default PreparedStatement and FileReader is there. ream(colIndex, (colIndex, ream(colIndex, (colIndex,
fileReaderObj, fileReaderObj, fileReaderObj, fileInputStreamOb
file.length()); file.length()); file.length()); j, file.length());

355 9 Consider a table with name – student and database as 4


admission. The student table have fields like stdId, stdName,
stdMarks(float). Write a java program that adds 2 records using
PreparedStatement. [have to write connection code here.]

356 9 Management of the LJ wants to do compilation of total marks of 6


the students. For this they do the following process.
1. Table - mse_marks with columns - roll_no, t1, t2, bonus.
2. Table – final_marks with roll_no, total ( where total = (t1+t2)/2
+ bonus )
Process 1: Need to fetch all the details from the table mse_marks
using CallableStatement. Write SQL code an Java code for the
same. Procedure name is getMarks().

Process 2: Need to insert same roll_no fetched from the


mse_marks to final_marks table and total after calculating it
perfectly from the table mse_marks.
This insertion query you have to write using PreparedStatement.

357 9 Write the java program that do connection with database 3


358 9 Write a java program to insert book_id, book_name, book_price 4
in the book table with LJU database. Do this using Statement

359 9 Write a java program to insert book_name, book_price in the 4


book table with LJU database. Do this using Statement. Here,
Book id is auto incremented. So do accordingly.
360 9 Write a java program to insert brochure_id brochure_name, 4
brochure_pages in the brochure table with LJU database. Do this
using Statement Interface. Take necessary data from user for
inserting atleast 5 records.
361 9 Write a java program to update book_price by book_name in 4
the book table with LJU database. Do this using Statement. Here,
Book id is auto incremented. So do accordingly.
362 9 Write a java program to update book_price and book_name in 4
the book table with LJU database. Do this using Statement. To do
this, First ask user to enter book_id. And then ask new book
name and price to be updated.
363 9 Write a java program to delete books from the book table 4
book_name in the book table with LJU database. Do this using
Statement.
364 9 Write a java program to display all brochures from the brochure 4
table where table contains columns like : brochure_id,
brochure_name, brochure_pages.
365 9 Ask User to do the following taks in book table. All the details of 6
table are given in above examples.
1 - for insertion
2 - for deletion by book name
3 - for update book name and price both BY book id.
4. for show all books from the table.
Do above program using switch case and untill user press - 5 -
ask them again do the above operations.
366 9 Write a java program that inserts record of employees like 4
emp_id, emp_name, emp_designation, emp_salary. Here
emp_id is primary key and auto incremented. Table name is
employee. And Database is : LJU.
Now, insert one record using PreparedStatement
367 9 Write a java program that inserts record of employees like 5
emp_id, emp_name, emp_designation, emp_salary. Here
emp_id is primary key and auto incremented. Table name is
employee. And Database is : LJU.
Now, insert one record using PreparedStatement. Ask User how
many records you want to enter. And insert n - records using
prepared statement
Page 39 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
368 9 Write a java program for the above same employee table - to do 4
upate emp designation and salary BY emp_name. Take all details
from user and update this by using PreparedStatement

369 9 Write a java program for the above same employee table - to do 4
delete employee those having salary more than salary entered
by user. from the table. Take all details from user and update
this by using PreparedStatement. - Take salary from user.

370 9 Write a java program that fetch all details of employees from 5
employee table.
Table name is employee. And Database is : LJU.
Now, fetch record using CallableStatement. - Create procedure
with name : getEmployees() Emp id is auto incremented.

371 9 Write a java program that inserts record of employees like 5


emp_id, emp_name, emp_designation, emp_salary. Here
emp_id is primary key and auto incremented. Table name is
employee. And Database is : LJU.
Now, insert one record using CallableStatement. - Create
procedure with name : insertEmployee(?,?,?) Emp id is auto
incremented. Consider all parameters as IN parameter

372 9 Write a java program that update record of emp_designation, 5


and emp_salary where emp_name is rahul. Here emp_id is
primary key and auto incremented. Table name is employee.
And Database is : LJU.
Now, update record using CallableStatement. - Create procedure
with name : updateEmployeeByName(?,?,?) Emp id is auto
incremented. Consider all parameters as IN parameter.
373 9 Write a java program that select record emp_designation, and 5
emp_salary where emp_name is rahul. Here emp_id is primary
key and auto incremented. Table name is employee. And
Database is : LJU.
Now, update record using CallableStatement. - Create procedure
with name : selectEmployeeByName(?,?,?) Emp id is auto
incremented.
Here : emp_name is IN parameter. emp_designation and
emp_salary are OUT parameter.

374 9 Consider Bank table with attributes AccountNo,CustomerName, 5


Balance, Phone and Address. Write a database application which
allows insertion, updation and deletion of records in Bank table.
Print values of all customers whose balance is greater than
20,000.

375 9 Write a program using JDBC for getting personal information – 5


name, birthdate, sex, address, phone no, email-id & store it in
database. Also provide list of all records, all male, all female & all
minors (age below 18).

376 9 Write Java application program to change the basic = basic + 500 5
of all the employees whose age is greater then 40 from
employee table then display how many record updated.

Page 40 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
377 9 Write a java code that used to insert Products in the product 5
table and update product price by product name.

378 9 Write a stroed procedure with name multiProduct(?,?,?) 3


This do the follwong.
- update product price by product id
- return the product name which is updated by us in previous
query.
- So here write both queries in a single procedure call. Use 3 - IN
and OUT parameter as per your understanding.

379 9 Write a Java code for the following task. 6


- Table Name : student : std_id, std_roll_no, std_name,
std_marks, std_div
- DB : LJU
- Insert 5 Records using prepared statement.
- Update Div of students having marks > 50 - To - Div B - Use
callable statement for this
380 9 Write a java code for the below tasks. 6
- Table Name : student : std_id, std_roll_no, std_name,
std_marks, std_div
- DB Name : LJU
- Write tow callable stored procedure with below names.
A) getMakrs(): this procedure will give you marks of students
from name.
B) updateRollNo() : this procedure will update the roll no by
giving the name of the student.

381 9 Write a java code to fetch all student's marks from the table and 3
do addition of all marks.
382 9 Write a java code to update student's marks in the follwing 4
manner.
Students having makrs > 50 add + 5 in total
marks > 60 add + 10
marks > 80 add + 15 in the marks and update the table in it.

383 9 Assume you are building an online bookstore application that allows 6
customers to purchase books. You have decided to use JDBC to handle
database operations. The application should have the following
functionality:
Add books to the database
Retrieve a list of books from the database
Update book information in the database
Delete a book from the database
Requirements:
The program should establish a connection to the database using JDBC. The
program should allow users to enter book information such as title, author,
publisher, and price. The program should use PreparedStatement to insert,
update and delete data from the database. The program should use
Statement to retrieve data from the database. The program should display
the list of books retrieved from the database. The program should handle
exceptions such as SQLException and ClassNotFoundException.
Functionality:
The program should provide a menu to the user to perform CRUD
operations on the book database. The program should handle input
validation for book information such as non-null values, valid prices, and
book title length. The program should display a success or failure message
after each CRUD operation.

Page 41 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
384 9 Suppose you are working on a project for a banking system that 6
requires you to implement JDBC CRUD operations. You need to create
a Java application that allows users to add, view, update, and delete
customer accounts from the database. The program should establish a
connection to the database using JDBC and use PreparedStatement to
execute SQL statements.
Requirements:
The program should establish a connection to the database using JDBC.
The program should allow users to add, view, update, and delete
customer accounts from the database.
The program should use PreparedStatement to execute SQL
statements.
The program should display appropriate messages to the user
indicating the success or failure of the operation.
Functionality:
The program should provide a menu to the user to add, view, update,
and delete customer accounts.
The program should handle exceptions such as SQLException and
ClassNotFoundException.

385 10 What is the correct syntax to fetch image content data from C 1 ImageContent ic Clob cb = Blob bb = BlobContent bc =
database table? = rs.getClob(“fileCo rs.getBlob(“fileCo rs.getBlobContent
rs.getImageConte ntent”); ntent”); (“file”);
nt(“fileContent”);

386 10 What does the setAutoCommit(false) ? D 1 Never commit Transaction is Transactions will B & C
the transactions. explicitly not be committed
committed. automatically
after each query.

387 10 Which of the following methods is used to get the data type of a A 1 getColumnTypeNa getColumnType() getColumnTypeNa getColumnName()
column in a ResultSet using ResultSetMetaData in Java? me() meData()

388 10 Which of the following methods is used to determine the size of A 1 length() size() getSize() getLength()
a Blob in Java?
389 10 Which of the following methods is used to retrieve a file as a C 1 executeUpdate() executeQuery() getBytes() getBinaryStream()
byte array from a database using JDBC in Java?
390 10 Which of the following data types is used to store binary data in D 1 DATE VARCHAR CLOB BLOB
a database using JDBC in Java?
391 10 Which of the following methods is used to insert a file into a C 1 setBlob() setBinaryStream() setClob() setCharacterStrea
database as a CLOB using JDBC in Java? m()
392 10 Which of the following methods is used to retrieve a file stored A 1 getBlob() getBinaryStream() getBytes() getCharacterStrea
as a BLOB from a database using JDBC in Java? m()
393 10 Which of the following methods is used to insert a file into a A 1 setBlob() setBinaryStream() setBytes() setCharacterStrea
database as a BLOB using JDBC in Java? m()

394 10 Which of the following interfaces provides methods for A 1 ResultSetMetaDat DatabaseMetaDat StatementMetaDa DBMetaData
retrieving metadata about a ResultSet object? a a ta
395 10 Which of the following interfaces provides methods for B 1 ResultSetMetaDat DatabaseMetaDat StatementMetaDa DBMetaData
retrieving metadata about a database? a a ta

396 10 What is the output of the following Java code that uses D 1 "Java Database The code will The code will "MySQL" will be
DatabaseMetaData to retrieve the database product name? Connectivity" will throw an throw a printed to the
import java.sql.*; be printed to the SQLException ClassNotFoundExc console.
console. because the JDBC eption because
public class Main { driver is not the MySQL JDBC
public static void main(String[] args) throws SQLException { compatible with driver is not
Connection conn = MySQL. found.
DriverManager.getConnection("jdbc:mysql://localhost:3306/myd
atabase", "root", "password");
DatabaseMetaData metadata = conn.getMetaData();
System.out.println(metadata.getDatabaseProductName());
conn.close();
}
}
Assume that the JDBC driver is for a MySQL database.

Page 42 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
397 10 What is the output of the following Java code that uses A 1 The column The code will The code will The code will
ResultSetMetaData to retrieve the column names of a ResultSet? names "id", throw an throw a throw a
import java.sql.*; "name", SQLException ClassNotFoundExc NullPointerExcepti
public class Main { "address", "city", because the SQL eption because on because the
public static void main(String[] args) throws SQLException { and "country" will query is invalid. the MySQL JDBC ResultSet is not
Connection conn = be printed to the driver is not initialized.
DriverManager.getConnection("jdbc:mysql://localhost:3306/myd console. found.
atabase", "root", "password");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM
customers");
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.println(rsmd.getColumnName(i)); }
conn.close(); } }
Assume that the "customers" table has columns "id", "name",
"address", "city", and "country".

398 10 What is the output of the following Java code that uses A 1 5 will be printed 4 will be printed The code will The code will
ResultSetMetaData to retrieve the number of columns in a to the console. to the console. throw an throw a
ResultSet? SQLException ClassNotFoundExc
import java.sql.*; because the SQL eption because
public class Main { query is invalid. the MySQL JDBC
public static void main(String[] args) throws SQLException { driver is not
Connection conn = found.
DriverManager.getConnection("jdbc:mysql://localhost:3306/myd
atabase", "root", "password");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM
customers");
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println(rsmd.getColumnCount());
conn.close(); } }
Assume that the "customers" table has columns "id", "name",
"address", "city", and "country".

399 10 DatabaseMetaData interface is used to get? A 1 Comprehensive Comprehensive Comprehensive Both b and c
information information information
about the about the table about the column
database as a as a whole. as a whole.
whole.
400 10 Which data type is used to store files in the database table? B 1 BLOB CLOB File Both a and b

401 10 What is blob in the following statement? C 1 Variable Object Data type Keyword
create table profilepic(photo blob);
402 10 Which statement(s) is/ are true about transactions? C 1 Only i and ii Only i and iii Only i, ii, and iv All the above
i. A transaction is a set of one or more SQL statements that make
up a logical unit of work.

ii. A transaction ends with either a commit or a rollback,


depending on whether there are any problems with data
consistency or data concurrency.

iii. A lock is a mechanism that allows two transactions from


manipulating the same data at the same time.

iv. To avoid conflicts during a transaction, a DBMS uses locks,


mechanisms for blocking access by others to the data that is
being accessed by the transaction.
403 10 Which method Drops all changes made since the previous A 1 public void public void public void close() public Statement
commit/rollback? rollback() commit() createStatement()

404 10 Which methods returns a stream that simply provides the raw B 1 getCharacterStrea getBinaryStream getAsciiStream getUnicodeStrea
bytes from the database without any conversion? m m

Page 43 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
405 10 I try to hack the system of Adhar card. For this somehow, I got 4
the access of the database – “aadhar” and it’s table –
“aadharDetails”.
Now can you help me with the following?
1 – To find the total number of columns in this table
2 – To find the name of the column 1 and 2
3 – To find the name of the column type of column 3 and 4.

Write the java code for the above mentioned tasks. [No need to
write code for connection]

406 10 Write a java code snippet that checks weather the database 4
connection is established or not? If the connection is established
perfectly then it should give us the version of the driver which I
have used for the connection.

407 10 Write database application that prints different records from a 4


table. Find out the name of table, no. of columns, no. of records
and type of the columns. Here DB name is LJU and Table is
employee with emp_id, emp_name, emp_designation,
emp_salary

408 10 Write a java code to insert image in table with name img_table 5
where columns are img_id, img_name, img_size, img_content.

409 10 Write a java code to retrive image in table with name img_table 5
where columns are img_id, img_name, img_size, img_content.

410 10 Write a java code to insert text file or java file in table with 5
name file_table where columns are file_id, file_name, file_size,
file_content, file_extension
411 10 Write a java code to retrieval text file or java file in table with 5
name file_table where columns are file_id, file_name, file_size,
file_content, file_extension

412 10 Project Definition: You are developing a Java program for a small business that 7
requires storing and retrieving employee data and their profile images using JDBC.
The program should allow authorized HR staff to add, retrieve, and delete
employee data from the database. Additionally, the program should store and
retrieve profile images for each employee.
Requirements:
The program should establish a connection to the database using JDBC.
The program should create a table if it doesn't exist and use the table for storing
and retrieving employee data.The program should allow authorized HR staff to add
employee data to the table.
The program should allow authorized HR staff to retrieve employee data from the
table based on a specified employee ID.The program should allow authorized HR
staff to delete employee data from the table based on a specified employee ID.The
program should store and retrieve profile images using the Blob data type in
JDBC.The program should handle exceptions such as SQLException and
IOException.
Functionalities:
Add employee data (employee ID, name, department, designation, and profile
image) Retrieve employee data (employee ID, name, department, designation, and
profile image) Delete employee data (employee ID)
Exit the program

413 10 Table name: product 5


Columns: pId, pName, pPrice, pCategory

Create a java program through which user can ask for the
following.
Enter 1 to know Number of Column
Enter 2 to know the Table Name
Enter 3 to know Column Name & Ask for Index of column
Enter 4 to know the type of column of Index given by user

414 10 DB Name : LJU 5

Create a java program through which user can ask for the
following.
Enter 1 to know Driver Name
Enter 2 to know the USer Name
Enter 3 to know Database Product Name
Enter 4 to know the Driver Version Page 44 of 45
L.J Institute of Engineering and Technology, Ahmedabad.
Computer Programming using Java-II Question Bank (SEM-II-2023 CE/IT/CSD/AIML/AIDS/RAI/CS&IT/CSE/CST/CEA Engineering)
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.

Unit MCQ
Sr No Question_Text Marks Option A Option B Option C Option D
Number Answer
415 10 Write a java program for the following tasks 5
The program should establish a connection to the database using JDBC.
The program should allow users to enter the source account number,
destination account number, and the amount to be transferred.
The program should begin a transaction and deduct the amount from the
source account and add the amount to the destination account.
The program should commit the transaction if the transaction is
successful. The program should rollback the transaction if any exception
occurs during the transaction.
Functionality:
The program should provide a menu to the user to perform the transfer
of funds. The program should handle exceptions such as SQLException
and ClassNotFoundException.
Create Two Tables:
account : acc_no & acc_balance
transaction : trans_id, ,src_acc_no, dest_acc_no, trans_amt
OUTPUT
Welcome to the Fund Transfer System.
1. Transfer Funds
2. Exit
416 10 Enter
Create your choice: 1
a Transaction Management System that uses Thread, 5
Where one thread is used to deposite in account and other
thread is used to withdraw from the account. You need to run
both thread on the wishes of user in database. Try to use
synchronized keywotrd to avoid deadlock.

417 10 Write a java code that stores .java file in the file table 4
418 10 Write a java code that retreives file with .java extension only 4
from the table and create a new file.
419 10 Write a java code that is retrive file that contains .txt file from 5
table and convert new file in d:/java location with same name
stored in table but extension with .java

Page 45 of 45

You might also like