Database Questions and Answers – Access SQL From a Programming Language

This set of Database Multiple Choice Questions & Answers focuses on “Access SQL From a Programming Language”.

1. Which of the following is used to access the database server at the time of executing the program and get the data from the server accordingly?
a) Embedded SQL
b) Dynamic SQL
c) SQL declarations
d) SQL data analysis
View Answer

Answer: b
Explanation: Embedded SQL, the SQL statements are identified at compile time using a preprocessor. The preprocessor submits the SQL statements to the database system for precompilation and optimization; then it replaces the SQL statements in the application program with appropriate code and function calls before invoking the programming-language compiler.

2. Which of the following header must be included in java program to establish database connectivity using JDBC ?
a) Import java.sql.*;
b) Import java.sql.odbc.jdbc.*;
c) Import java.jdbc.*;
d) Import java.sql.jdbc.*;
View Answer

Answer: a
Explanation: The Java program must import java.sql.*, which contains the interface definitions for the functionality provided by JDBC.

3. DriverManager.getConnection(_______ , ______ , ______)
What are the two parameters that are included?
a) URL or machine name where server runs, Password, User ID
b) URL or machine name where server runs, User ID, Password
c) User ID, Password, URL or machine name where server runs
d) Password, URL or machine name where server runs, User ID
View Answer

Answer: b
Explanation: The database must be opened first in order to perform any operations for which this get connection method is used.

4. Which of the following invokes functions in sql?
a) Prepared Statements
b) Connection statement
c) Callable statements
d) All of the mentioned
View Answer

Answer: c
Explanation: JDBC provides a Callable Statement interface that allows invocation of SQL stored procedures and functions.

5. Which of the following function is used to find the column count of the particular resultset?
a) getMetaData()
b) Metadata()
c) getColumn()
d) get Count()
View Answer

Answer: a
Explanation: The interface ResultSet
has a method, getMetaData(), that returns a ResultSetMetaData object that contains metadata about the result set. ResultSetMetaData, in turn, has methods to find metadata information, such as the number of columns in the result, the name of a specified column, or the type of a specified column.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which of the following is a following statement is a prepared statements?
a) Insert into department values(?,?,?)
b) Insert into department values(x,x,x)
c) SQLSetConnectOption(conn, SQL AUTOCOMMIT, 0)
d) SQLTransact(conn, SQL ROLLBACK)
View Answer

Answer: a
Explanation:? is used as a placeholder whose value can be provided later.

7. Which of the following is used as the embedded SQL in COBOL?
a) EXEC SQL <embedded SQL statement >;
b) EXEC SQL <embedded SQL statement > END-EXEC
c) EXEC SQL <embedded SQL statement >
d) EXEC SQL <embedded SQL statement > END EXEC;
View Answer

Answer: b
Explanation: EXEC SQL <embedded SQL statement >; is normally in C.

8. Which of the following is used to distinguish the variables in SQL from the host language variables?
a) .
b) –
c) :
d) ,
View Answer

Answer: c

DECLARE c cursor FOR
FROM student
WHERE tot cred > :credit amount;



9. The update statement can be executed in host language using
a) EXEC SQL update c;
b) EXEC SQL update c into :si, :sn;

   UPDATE instructor
   SET salary = salary + 100

d) EXEC SQL update END-SQL
View Answer

Answer: c
Explanation: The SQL can be terminated by ; to terminate the sentence.

10. Which of the following is used to access large objects from a database ?
a) setBlob()
b) getBlob()
c) getClob()
d) all of the mentioned
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – Database Management System.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.