JDBC Flashcards

1
Q

What is JDBC?

A

Java™ database connectivity (JDBC) is the JavaSoft specification of a standard application programming interface (API) that allows Java programs to access database management systems. The JDBC API consists of a set of interfaces and classes written in the Java programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the core interfaces / classes in JDBC?

A

DriverManager, Connection, PreparedStatement, CallableStatement, ResultSet, ParameterMetaData, ResultSetMetaData, RowId, SQLException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a stored procedure and how would you call it in Java?

A

A stored procedure is a user defined piece of code written in SQL which may return a value that is invoked by calling it explicitly.

You can call the stored procedure by doing the following:

Invoke the connection.preparecall method to create a callable statement object
,Invoke callable statement object,
Invoke callablestatement.registeroutparameter,
Invoke callablestatement.get,
Invoke callablestatement.close

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between Statement and PreparedStatement?

A

The Key Difference between Statement and PreparedStatement is that Statement is used for executing simple SQL Statements whereas PreparedStatement is used for executing dynamic and pre-compiled SQL Statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Steps to executing an SQL query using JDBC?

A
  1. Establishing a connection.
  2. Create a statement.
  3. Execute the query.
  4. Process the ResultSet object.
  5. Close the connection.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to execute stored procedures using JDBC?

A
  1. Prepare the callable statement by using Connection.prepareCall().
  2. Register the output parameters (if any exist)

3.Set the input parameters (if any exist)

  1. Execute the CallableStatement, and retrieve any result sets or output parameters.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which interface is responsible for transaction management?

A

Connection interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly