JDBC interview questions
Posted by mtwinkle on May 18, 2006
Q. What are 4 drivers available in JDBC and What situation , each of the 4 drivers used ?
Type 1: JDBC-ODBC Bridge The type 1 driver, JDBC-ODBC Bridge, translates all JDBC calls into ODBC (Open DataBase Connectivity) calls and sends them to the ODBC driver. As such, the ODBC driver, as well as, in many cases, the client database code, must be present on the client machine. May be used when an ODBC driver has already been installed on client machine and performance is not an issue.
Type 2: Native-API/partly Java driver JDBC driver type 2 — the native-API/partly Java driver — converts JDBC calls into database-specific calls for databases such as SQL Server, Informix, Oracle, or Sybase. The type 2 driver communicates directly with the database server; therefore it requires that some binary code be present on the client machine. Can be used when application is not for internet.
Type 3: Net-protocol/all-Java driver JDBC driver type 3 — the net-protocol/all-Java driver — follows a three-tiered approach whereby the JDBC database requests are passed through the network to the middle-tier server. The middle-tier server then translates the request (directly or indirectly) to the database-specific native-connectivity interface to further the request to the database server. If the middle-tier server is written in Java, it can use a type 1 or type 2 JDBC driver to do this.Type 3 drivers are best suited for environments that need to provide connectivity to a variety of DBMS servers and heterogeneous databases and that require significantly high levels of concurrently connected users where performance and scalability are major concerns.
Type 4: Native-protocol/all-Java driver The native-protocol/all-Java driver (JDBC driver type 4) converts JDBC calls into the vendor-specific database management system (DBMS) protocol so that client applications can communicate directly with the database server. Level 4 drivers are completely implemented in Java to achieve platform independence and eliminate deployment administration issues. Useful for Internet-related applications.
Q. Prepared statement?
Ans. Prepared statements are pre-compiled statements. It is mainly used to speed up the process of inserting/ deleting/ updating , especially when there is a bulk processing.
Q. Callable statement?
Ans. Used to invoke the stored procedures.
con.prepareCall(String sql, int resultSetType, int resultSetConcurrency)
JDBC-ODBC bridge is NOT multi-threaded
It does NOT support multiple open statements per connection.