Documente Academic
Documente Profesional
Documente Cultură
JDBC Architecture
JDBC API available in java.sql and javax.sql packages JDBC Drivers classes available from different vendors which must be registered with JDBC DriverManager to connect to different databases
Close
Stage 1: Connect
Connect Query Process results Register the driver Connect to the database
Close
Class.forName(oracle.jdbc.driver.Or acleDriver); 2. Connect to the database. Connection conn = DriverManager.getConnection (URL, conn = DriverManager.getConnection Connection userid, password);
("jdbc:oracle:thin:@myhost:1521:orcl", "scott", "tiger");
Protocol
Subprotocol
Database identifier
jdbc:oracle:<driver>:@<database>
jdbc:oracle:thin:@<host>:<port>:<SID>
jdbc:oracle:thin:@localhost:1521:XE
Using Connection
java.sql.Connection
Stage 2: Query
Connect Query Create a statement Query the database
Process results
Close
Process results
Close
Stage 4: Close
Connect Query Close the result set Process results Close the statement
Close
JDBC Drivers
Type 1 - JDBC-ODBC Bridge driver Type 2 - Native-API/partly Java driver Type 3 - All Java/Net-protocol driver Type 4 - Native-protocol/all-Java driver
The Type 4 drivers take JDBC calls and translates them into the network protocol using java networking libraries to communicate directly with the database server.