JDBC Drivers. Converts the client request to a db understandable, nativeformat and present it to db.. Converts the response to the Java format and presented to theclient.
JDBC Type 1 Driver (JDBC-ODBC Bridge)Advantages : MS Access or Microsoft SQL ServerDisadvantages: don’t support software installation on client native ODBC libraries must reside on the server =>reduces the performance
JDBC Type 2 Driver (Native-API partly Java Driver)Advantages : Faster than Type 1Disadvantages: don’t support software installation on client
JDBC Type 3 Driver (JDBC Net pure Java Driver)Converts JDBC calls into a DBMS-independent network protocol,which is translated to database-specific calls by a middle-tierserver.Advantages : The most flexible type, High adaptability, controlunderlying database without modifying the client side driver.Disadvantages: Database-specific code needs to be executed in themiddle- tier server. Needs to implement security like firewalls.
JDBC Type 4 Driver (Native-protocol pure Java Driver, Java to DBProtocol)Convert JDBC calls into the network protocol that communicatesdirectly with the database.Advantages : Communicate directly with the db engine using JavaSockets. Fastest JDBC drivers available. No addition on clients.Disadvantages: database-specific
Creating statement and queries Statement interface Statement PreparedStatement CallableStatement connection.createStatement() PreparedStatement pstmt = cn.prepareStatement(“Select * from ToppingDetails”);
executeQuery() & ResultSet object connection.createStatement() PreparedStatement pstmt = cn.prepareStatement(“Select * from ToppingDetails”); ResultSet rs = pstmt.executeQuery();executeUpdate() INSERT, DELETE, UPDATE, SQL DDL (Data DefinitionLanguage) return int value : row countexecute() Return more than one result set Return true if a result set object is generated
Processing queries Data in the ResultSet is in a tabular format. The initial cursor is positioned before the first row Traverse using next() method. next() return : true if the current cursor position is on a valid row false if the cursor is placed at a position after the last row
Extract the data getString() getInt() getFloat() getObject()
Closing the Database Connection close() method is provided by the Connection,Statement, ResultSet objects. rs.close(); pstmt.close(); cn.close();