JDBC Flashcards
What is JDBC?
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.
What are the core interfaces / classes in JDBC?
DriverManager, Connection, PreparedStatement, CallableStatement, ResultSet, ParameterMetaData, ResultSetMetaData, RowId, SQLException
What is a stored procedure and how would you call it in Java?
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
What is the difference between Statement and PreparedStatement?
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
Steps to executing an SQL query using JDBC?
- Establishing a connection.
- Create a statement.
- Execute the query.
- Process the ResultSet object.
- Close the connection.
How to execute stored procedures using JDBC?
- Prepare the callable statement by using Connection.prepareCall().
- Register the output parameters (if any exist)
3.Set the input parameters (if any exist)
- Execute the CallableStatement, and retrieve any result sets or output parameters.
Which interface is responsible for transaction management?
Connection interface