jdbc-130913021409-phpapp01000988www.pptx
Discussions
⦿What is JDBC?
⦿What is ODBC?
⦿JDBC vs ODBC?
⦿ Architecture of JDBC.
⦿ Types of JDBC driver available.
⦿ Steps to connect to DB.
⦿ Types of Statement.
What is JDBC ?
⦿ JDBC acronym of Java Database
connectivity; though Sun Microsystems
⦿JDBC is a standard java API for
independent database connection
between a java program and wide range
of relational database.
⦿It is present in the “java.sql” package
 JDBC is an interface between Java and Database
 JDBC receives queries from Java Application program and
communicate with Database
 All the communications are in the form of SQL commands
 JDBC is reponsible for
 Open a Connection
 Communicate with database
 Execute SQL statements
 Retrive query results
What is JDBC ?
Open DataBase Connectivity (ODBC)
 Standard designed by Microsoft to interact with
databases
 ODBC is packed with many features and extending
support for all type of databases
 ODBC provides multiple mechanism for performing
single task and number of data handling capabilities
JDBC vs ODBC
 JDBC and ODBC are X/OPEN call level interface
for SQL
 JDBC is not a derivative of ODBC
 JDBC is compact and simple
 JDBC is meant for simple access to the database and
difficult task at least make possible
Architecture of JDBC
JDBC Drivers
 JDBC driver is responsible for making connection with different
databases
 It is also translating the queries received from Application and
submit into database
 A reverse translation is also required to perform by the Driver
 JDBC Driver speaks JAVA to Application and native language
to database
 JDBC Drivers are exists for almost all databases
 Appropriate driver will load for requied database
Types of JDBC driver
⦿Type 1; jdbc-odbc bridge driver
⦿Type 2; native API partly java driver.
⦿Type 3; net protocols all java driver.
⦿ Type 4; native protocols all java driver.
JDBC – ODBC Bridge
 It is a JDBC driver designed to let Java application
communicate with database via an underlying ODBC driver
 It is called Type I JDBC connector
 It can be used with multiple databases and is vendor
independent
 This type JDBC driver speaks only to ODBC driver, hence
works for Databases supported by ODBC
 One more added layer is used and hence more complex and
slower than JDBC drivers
Native-API-Partly-Java Driver
 It make use of local native libraries to communicate
with database
 Vendor specific Call Level Interface(CLI) installed
locally are used by this type driver
 CLI libraries are actually communicate with
database
 Application level requests are translated into
equallent native method call of CLI
 Faster than Type I driver
JDBC-Net-All-Java Driver
 Type III Driver, uses the CLI libraries locates in a remote server
 Type III driver has two major components
 An All-Java portion that can download to the client
 Server portion containing both Java and Native methods
 All communication between Application and Database is 100%
Java to Java
 This type of driver is also depending on CLI calls, which is
installed on Server
 Type III can be used in Internet, since no direct access to CLI
libraries
 Type III Network protocol is not standardized
Native-Protocol-All-Java Driver
 100% java specific drivers
 No intermediate translation is required
 But all vendor specific driver cannot released by
Java
 Java Applets are now free from Acces restrictions
Steps to connect?
⦿Define the connection URL.
⦿Established the connection.
⦿ Create the Statement object.
⦿Execute a query.
⦿Process the results.
⦿Close the connection.
Steps to connect?
⦿Define the connection url :
Class.forName();
⦿ For jdbc-odbc bridge driver:-
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
⦿ For oracle driver:-
Class.forName(“oracle.jdbc.driver.OracleDriver”);
⦿ For My sql driver:-
Class.forName(“com.mysql.jdbc.Driver”);
Steps to connect?
⦿ Established the connection:
Connection con
=DriverManager.getConnection(“url”,”user_name”,”pass”);
Steps to connect?
⦿ Create the Statement object:
Statement stmt=con.createStatement();
Steps to connect?
⦿Execute the query:
 For the SELECT query:-
 String sql=“SELECT * FROM EMP”;
 stmt.executeQuery(sql);
 For the INSERT/UPDATE query:-
 String sql=“INSERT INTO EMP VALUES(47,’TEDDY’)”;
 stmt.executeUpdate(sql);
Steps to connect?
⦿Process the result:-
ResultSet rs=stmt.execute Query(sql);
while(rs.next()){
System.out.println(rs.getInt(id));
System.out.print(rs.getString(name));
}
Steps to connect?
⦿Close the connection
release all the resources that the connection
is holding.
stmt.close();
con.close();
Steps to connect?
⦿ Summarizing the steps for connecting java DB and inserting values in
DB
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
con=DriverManager.getConnection("jdbc:derby://localhost:1527/orbac
us","teddy","teddy");
Statement
stmt=con.createStatement();
String sql=“INSERT INTO
TEDDY(47,’jani’)”;
stmt.executeUpdate(sql);
stmt.close();
con.close();
Types of Statement available
⦿There are three types of Statement
available in Statement class:-
 Statement
 PreparedStatement
 CallableStatement
Types of Statement available
⦿Statement
This represent a simple sql/mysql
statement.
Statement stmt=con.createStatement();
Types of Statement available
⦿PreparedStatement
this represent precompiled sql/my sql
statement which allows improved
performance. It allows to execute the query
multiple times and we can set the values
according to our need.
PreparedStatement psmt=con.prepareStatement();
Types of Statement available
⦿CallableStatement
This allows the access of stored
procedures; that are stored on the database.
CallableStatement csmt=con.prepareCall();
Thank You

More Related Content

PDF
JDBC Presentation with JAVA code Examples.pdf
PPTX
Chapter_4_-_JDBC[1].pptx
PPT
PPTX
Jdbc introduction
PPTX
Advanced JAVA
PPT
4-INTERDUCATION TO JDBC-2019.ppt
PDF
PPTX
Jdbc new
JDBC Presentation with JAVA code Examples.pdf
Chapter_4_-_JDBC[1].pptx
Jdbc introduction
Advanced JAVA
4-INTERDUCATION TO JDBC-2019.ppt
Jdbc new

Similar to jdbc-130913021409-phpapp01000988www.pptx (20)

PPTX
Java database connectivity with MySql
PPTX
Java database connectivity with MySql
PPT
open data base connectivity and java database connectivity
PPT
JDBC java for learning java for learn.ppt
PDF
JDBC with MySQL.pdf
PDF
JDBC with MySQL.pdf
PPTX
java.pptx
PPT
java database connection (jdbc)
PPTX
Jdbc
PPTX
Jdbc driver types
PDF
unit8_jdbc.pdf mysql and java jdbc connection
DOC
jdbc document
PPTX
Java Database Connectivity (JDBC)
DOC
PPT
JDBC java database connectivity with dbms
PPTX
Core jdbc basics
PPT
JDBC.ppt
PPTX
jdbc.pptx jdbc.pptxjdbc.pptxjdbc.pptxjdb
Java database connectivity with MySql
Java database connectivity with MySql
open data base connectivity and java database connectivity
JDBC java for learning java for learn.ppt
JDBC with MySQL.pdf
JDBC with MySQL.pdf
java.pptx
java database connection (jdbc)
Jdbc
Jdbc driver types
unit8_jdbc.pdf mysql and java jdbc connection
jdbc document
Java Database Connectivity (JDBC)
JDBC java database connectivity with dbms
Core jdbc basics
JDBC.ppt
jdbc.pptx jdbc.pptxjdbc.pptxjdbc.pptxjdb
Ad

Recently uploaded (20)

PDF
African Communication Research: A review
PPTX
UNIT_2-__LIPIDS[1].pptx.................
PPT
hemostasis and its significance, physiology
PPTX
Theoretical for class.pptxgshdhddhdhdhgd
PPTX
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
PDF
Lecture on Viruses: Structure, Classification, Replication, Effects on Cells,...
PDF
BSc-Zoology-02Sem-DrVijay-Comparative anatomy of vertebrates.pdf
PPTX
Neurological complocations of systemic disease
PPTX
Neurology of Systemic disease all systems
PDF
Hospital Case Study .architecture design
PPTX
4. Diagnosis and treatment planning in RPD.pptx
PPTX
ACFE CERTIFICATION TRAINING ON LAW.pptx
PDF
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
PPTX
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
PPTX
operating_systems_presentations_delhi_nc
PDF
Review of Related Literature & Studies.pdf
PPTX
Q2 Week 1.pptx Lesson on Kahalagahan ng Pamilya sa Edukasyon
PDF
anganwadi services for the b.sc nursing and GNM
PPT
hsl powerpoint resource goyloveh feb 07.ppt
PDF
Chevening Scholarship Application and Interview Preparation Guide
African Communication Research: A review
UNIT_2-__LIPIDS[1].pptx.................
hemostasis and its significance, physiology
Theoretical for class.pptxgshdhddhdhdhgd
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
Lecture on Viruses: Structure, Classification, Replication, Effects on Cells,...
BSc-Zoology-02Sem-DrVijay-Comparative anatomy of vertebrates.pdf
Neurological complocations of systemic disease
Neurology of Systemic disease all systems
Hospital Case Study .architecture design
4. Diagnosis and treatment planning in RPD.pptx
ACFE CERTIFICATION TRAINING ON LAW.pptx
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
operating_systems_presentations_delhi_nc
Review of Related Literature & Studies.pdf
Q2 Week 1.pptx Lesson on Kahalagahan ng Pamilya sa Edukasyon
anganwadi services for the b.sc nursing and GNM
hsl powerpoint resource goyloveh feb 07.ppt
Chevening Scholarship Application and Interview Preparation Guide
Ad

jdbc-130913021409-phpapp01000988www.pptx

  • 2. Discussions ⦿What is JDBC? ⦿What is ODBC? ⦿JDBC vs ODBC? ⦿ Architecture of JDBC. ⦿ Types of JDBC driver available. ⦿ Steps to connect to DB. ⦿ Types of Statement.
  • 3. What is JDBC ? ⦿ JDBC acronym of Java Database connectivity; though Sun Microsystems ⦿JDBC is a standard java API for independent database connection between a java program and wide range of relational database. ⦿It is present in the “java.sql” package
  • 4.  JDBC is an interface between Java and Database  JDBC receives queries from Java Application program and communicate with Database  All the communications are in the form of SQL commands  JDBC is reponsible for  Open a Connection  Communicate with database  Execute SQL statements  Retrive query results What is JDBC ?
  • 5. Open DataBase Connectivity (ODBC)  Standard designed by Microsoft to interact with databases  ODBC is packed with many features and extending support for all type of databases  ODBC provides multiple mechanism for performing single task and number of data handling capabilities
  • 6. JDBC vs ODBC  JDBC and ODBC are X/OPEN call level interface for SQL  JDBC is not a derivative of ODBC  JDBC is compact and simple  JDBC is meant for simple access to the database and difficult task at least make possible
  • 8. JDBC Drivers  JDBC driver is responsible for making connection with different databases  It is also translating the queries received from Application and submit into database  A reverse translation is also required to perform by the Driver  JDBC Driver speaks JAVA to Application and native language to database  JDBC Drivers are exists for almost all databases  Appropriate driver will load for requied database
  • 9. Types of JDBC driver ⦿Type 1; jdbc-odbc bridge driver ⦿Type 2; native API partly java driver. ⦿Type 3; net protocols all java driver. ⦿ Type 4; native protocols all java driver.
  • 10. JDBC – ODBC Bridge  It is a JDBC driver designed to let Java application communicate with database via an underlying ODBC driver  It is called Type I JDBC connector  It can be used with multiple databases and is vendor independent  This type JDBC driver speaks only to ODBC driver, hence works for Databases supported by ODBC  One more added layer is used and hence more complex and slower than JDBC drivers
  • 11. Native-API-Partly-Java Driver  It make use of local native libraries to communicate with database  Vendor specific Call Level Interface(CLI) installed locally are used by this type driver  CLI libraries are actually communicate with database  Application level requests are translated into equallent native method call of CLI  Faster than Type I driver
  • 12. JDBC-Net-All-Java Driver  Type III Driver, uses the CLI libraries locates in a remote server  Type III driver has two major components  An All-Java portion that can download to the client  Server portion containing both Java and Native methods  All communication between Application and Database is 100% Java to Java  This type of driver is also depending on CLI calls, which is installed on Server  Type III can be used in Internet, since no direct access to CLI libraries  Type III Network protocol is not standardized
  • 13. Native-Protocol-All-Java Driver  100% java specific drivers  No intermediate translation is required  But all vendor specific driver cannot released by Java  Java Applets are now free from Acces restrictions
  • 14. Steps to connect? ⦿Define the connection URL. ⦿Established the connection. ⦿ Create the Statement object. ⦿Execute a query. ⦿Process the results. ⦿Close the connection.
  • 15. Steps to connect? ⦿Define the connection url : Class.forName(); ⦿ For jdbc-odbc bridge driver:- Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); ⦿ For oracle driver:- Class.forName(“oracle.jdbc.driver.OracleDriver”); ⦿ For My sql driver:- Class.forName(“com.mysql.jdbc.Driver”);
  • 16. Steps to connect? ⦿ Established the connection: Connection con =DriverManager.getConnection(“url”,”user_name”,”pass”);
  • 17. Steps to connect? ⦿ Create the Statement object: Statement stmt=con.createStatement();
  • 18. Steps to connect? ⦿Execute the query:  For the SELECT query:-  String sql=“SELECT * FROM EMP”;  stmt.executeQuery(sql);  For the INSERT/UPDATE query:-  String sql=“INSERT INTO EMP VALUES(47,’TEDDY’)”;  stmt.executeUpdate(sql);
  • 19. Steps to connect? ⦿Process the result:- ResultSet rs=stmt.execute Query(sql); while(rs.next()){ System.out.println(rs.getInt(id)); System.out.print(rs.getString(name)); }
  • 20. Steps to connect? ⦿Close the connection release all the resources that the connection is holding. stmt.close(); con.close();
  • 21. Steps to connect? ⦿ Summarizing the steps for connecting java DB and inserting values in DB Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/orbac us","teddy","teddy"); Statement stmt=con.createStatement(); String sql=“INSERT INTO TEDDY(47,’jani’)”; stmt.executeUpdate(sql); stmt.close(); con.close();
  • 22. Types of Statement available ⦿There are three types of Statement available in Statement class:-  Statement  PreparedStatement  CallableStatement
  • 23. Types of Statement available ⦿Statement This represent a simple sql/mysql statement. Statement stmt=con.createStatement();
  • 24. Types of Statement available ⦿PreparedStatement this represent precompiled sql/my sql statement which allows improved performance. It allows to execute the query multiple times and we can set the values according to our need. PreparedStatement psmt=con.prepareStatement();
  • 25. Types of Statement available ⦿CallableStatement This allows the access of stored procedures; that are stored on the database. CallableStatement csmt=con.prepareCall();