JDBC (Java Database Connectivity) allows Java applications to execute SQL statements. Learn the 5 steps of JDBC, Driver Types 1-4, and Java Servlet web basics.
1. The 4 JDBC Driver Types (Frequent Exam Question)
Driver Type
Name
Architecture & Performance
Type 1
JDBC-ODBC Bridge
Converts JDBC calls to ODBC calls. Requires ODBC driver installed on client machine. (Deprecated, slowest).
Type 2
Native-API Driver
Converts JDBC calls to native C/C++ client API of the database vendor. Requires vendor client software installed.
Type 3
Network-Protocol Driver
Middleware server converts JDBC calls into database-independent network protocol, then into vendor database protocol.
Type 4
Pure Java Thin Driver
Direct conversion of JDBC calls into vendor-specific network protocol written 100% in Java. (Fastest, no client installation required).
💡 Examiner Distinction Tip: Statement vs PreparedStatement
Always use PreparedStatement over Statement! Why?
1. Security: Prevents SQL Injection attacks by escaping parameter inputs.
2. Performance: The SQL query is pre-compiled by the database engine, allowing faster repeated execution with parameters.
3. Java Servlets & Web Application Basics
Servlets are Java server-side components that process HTTP client requests and return dynamic responses.
Servlet Lifecycle Methods:
init(ServletConfig config): Called once when the Servlet container loads the servlet into memory.
service(HttpServletRequest req, HttpServletResponse res): Called for every incoming request. Dispatches to doGet() or doPost().
destroy(): Called once when the server shuts down or unloads the servlet to free memory.
⚡ Quick Self-Test
Q: Why is Type 4 JDBC driver preferred over Type 1?
Answer: Type 4 is 100% Pure Java and communicates directly with the database protocol.
It requires no native client software or ODBC drivers to be pre-installed on the client machine, providing maximum portability and speed.