SlideShare a Scribd company logo
1 of 16
JDBC Connectivity Model
• Name: Kunj Desai
• Enrollment No.: 140950107022
• Branch : CSE-A
• Year:2017
Java and the database
• Database is used to store data. It is also
known as persistent storage as the data is
stored and can be retrieved anytime.
• Java and database are used almost
everywhere to store persistent data and
retrieve it when required.
SQL
• Information stored in the database is in tables
and the language used to query information
from the database is SQL.
• Using SQL we can query a table based on the
requirement.
DDL – DML – DCL - TCL
• DDL – Data Definition Language
– These queries are used to create database objects such as
tables, indexes, procedures, constraints
– Create , drop, alter,truncate,comment,rename
• DML – Data Manipulation Language
– These queries are used to manipulate the data in the database
tables.
– Insert, update, delete, select (more available)
• DCL – Data Control Language
– These are data control queries like grant and revoke
permissions
• TCL– Transaction Control Language
– These are transaction control queries like commit, revoke,
savepoint, set transaction
What is JDBC?
• JDBC provides Java applications with access to most database
systems via SQL
• The architecture and API closely resemble Microsoft's ODBC
• JDBC 1.0 was originally introduced into Java 1.1
– JDBC 2.0 was added to Java 1.2
• JDBC is based on SQL-92
• JDBC classes are contained within the java.sql package
– There are few classes
– There are several interfaces
Database Connectivity History
Before APIs like JDBC and ODBC,
database connectivity was tedious
• Each database vendor provided a function library for accessing
their database
• The connectivity library was proprietary.
• If the database vendor changed for the application, the data access
portions had to be rewritten
• If the application was poorly structured, rewriting its data access
might involve rewriting the majority of the application
• The costs incurred generally meant that application developers
were stuck with a particular database product for a given
application
JDBC Architecture
• With JDBC, the application programmer uses the JDBC API
– The developer never uses any proprietary APIs
• Any proprietary APIs are implemented by a JDBC driver
• There are 4 types of JDBC Drivers
Java Application
JDBC API
JDBC DriverManager
JDBC Driver JDBC Driver
JDBC Drivers
• Type 1 Driver - JDBC-ODBC bridge
– This is an ODBC driver, which is open source
• Type 2 Driver – Native API driver
– This is more like the OCI (Oracle Call Interface) call
interface is converted to native calls of the database.
• Type 3 Driver – Network protocol driver
– This is achieved by using a Java Driver in a middleware
• Type 4 Driver – Native Protocol Driver
– This is a driver written purely in Java Language
• We Usually prefer to depend on the Type 4 driver
– Eg: Oracle thin driver
Java-Oracle Example
public void ConnectToAndQueryDatabase
(String username, String password)
{
Connection con =
DriverManager.getConnection( "jdbc:myD
river:myDatabase", username, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT
a, b, c FROM Table1");
while (rs.next()) {
int x = rs.getInt("a");
String s = rs.getString("b");
float f = rs.getFloat("c");
}
}
•In the example we have a method call
ConnectTo And QueryDatabase which
takes in a username, password
•The Connection Interface creates a
connection. A connection is created by
using the DriverManager Class with the
connection string , username, password.
The concrete implementation is
OracleConnection.
•The statement Interface creates a
statement. The concrete implementation
is Oracle Statement.
•ResultSet stores the result after invoking
execute Query on the statement object.
We can iterate over the resultset to get
the results from table.
Statement and Prepared
Statement
• A Statement Interface is used to create a statement i.e.
a query to be executed against a database. In this
process, two calls are made to the database system ,
one to get the table metadata and other to get the
data itself. The statement object is also compiled every
time it executes.
• A Prepared statement comes in handy as it is compiled
and cached and only makes on database call when
invoked. The compilation would be skipped even if the
values in the where clause change
Statement and Prepared
Statement• Statement
Statement stmt= con.statment(“select * from mytab where num=22”);
• Prepared Statement
PreparedStatement pstmt = con.preparestatement(select * from mytab where num=?”);
pstmt.setInt(1,”11”);
This sets the value of ? as 11
– If we run the statement in for loop every time
changing the where clause, the statement is
compiled every time before execution.
– In the case of prepared statement , the prepared
statement is cached and compiled only one time in
the event of a for loop with changing where clause.
Stored Procedures
• Stored procedures are compiled sql programs
which are stored in the database system and
can be executed in the database.
• We use the call keyword in SQL to execute
stored procedures
• Java can access the stored procedures in the
database by using the Callable statements
Callable Statements
• Callable statements are used to call stored
procedures in the database.
CallableStatement cstmt = null;
try {
String SQL = "{call myprocedure(?, ?)}"; //? Can be set dynamically as in
prepared statement
cstmt = conn.prepareCall (SQL);
. . .
}
catch (SQLException e) {
. . .
}
finally {
. . .
}
JDBC Interfaces
• ResultSet
– Represents the result of an SQL statement
– Provides methods for navigating through the resulting data
• DatabaseMetaData
– Provides access to a database's system catalogue
• ResultSetMetaData
– Provides information about the data contained within a ResultSet
Transactions
• Transactions imply a situation when we have one
or more SQL statements to be committed only
when everything goes right
– Assume we have 10 databases which are always to be
in sync. So we would have one sql query to be
executed across all databases. So, the sql query
should committed in all the databases only after
successful execution in all 10 databases. This is called
a transaction. The transaction is committed only after
successful execution across all databases.
Closing Connections
• Always remember to close in the following
sequence.
– Resultset
– Statement/Prepared Statement
– Connections
• Do a null check always before closing the
connections using close() method.

More Related Content

What's hot

Java database connectivity
Java database connectivityJava database connectivity
Java database connectivityVaishali Modi
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivityTanmoy Barman
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database ConnectivityGary Yeh
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)suraj pandey
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)Maher Abdo
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...Pallepati Vasavi
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Pooja Talreja
 
Java.sql package
Java.sql packageJava.sql package
Java.sql packagemyrajendra
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05Ankit Dubey
 

What's hot (20)

java Jdbc
java Jdbc java Jdbc
java Jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Overview Of JDBC
Overview Of JDBCOverview Of JDBC
Overview Of JDBC
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
 
JDBC
JDBCJDBC
JDBC
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
 
JDBC
JDBCJDBC
JDBC
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
Jdbc driver types
Jdbc driver typesJdbc driver types
Jdbc driver types
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
 

Similar to JDBC Connectivity Model

Jdbc presentation
Jdbc presentationJdbc presentation
Jdbc presentationnrjoshiee
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivityVaishali Modi
 
4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.pptNaveenKumar648465
 
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004derek_clark_ashmore
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5Smita B Kumar
 
java.pptx
java.pptxjava.pptx
java.pptxbfgd1
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCSimba Technologies
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivityarikazukito
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptkingkolju
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part ISivaSankari36
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsTeamstudio
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programmingchhaichivon
 

Similar to JDBC Connectivity Model (20)

Jdbc presentation
Jdbc presentationJdbc presentation
Jdbc presentation
 
Unit 5.pdf
Unit 5.pdfUnit 5.pdf
Unit 5.pdf
 
Jdbc
JdbcJdbc
Jdbc
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Jdbc
JdbcJdbc
Jdbc
 
4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt4-INTERDUCATION TO JDBC-2019.ppt
4-INTERDUCATION TO JDBC-2019.ppt
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
 
Jdbc
JdbcJdbc
Jdbc
 
java.pptx
java.pptxjava.pptx
java.pptx
 
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBCBI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC
 
Jdbc connectivity
Jdbc connectivityJdbc connectivity
Jdbc connectivity
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 
java 4 Part 1 computer science.pptx
java 4 Part 1 computer science.pptxjava 4 Part 1 computer science.pptx
java 4 Part 1 computer science.pptx
 
Jdbc
JdbcJdbc
Jdbc
 

More from kunj desai

OLAP operations
OLAP operationsOLAP operations
OLAP operationskunj desai
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsingkunj desai
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkerskunj desai
 
Introduction to 8085 microprocessor
Introduction to 8085 microprocessorIntroduction to 8085 microprocessor
Introduction to 8085 microprocessorkunj desai
 
Custom Controls in ASP.net
Custom Controls in ASP.netCustom Controls in ASP.net
Custom Controls in ASP.netkunj desai
 
Requirement specification (SRS)
Requirement specification (SRS)Requirement specification (SRS)
Requirement specification (SRS)kunj desai
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFAkunj desai
 
php databse handling
php databse handlingphp databse handling
php databse handlingkunj desai
 
Concept of constructors
Concept of constructorsConcept of constructors
Concept of constructorskunj desai
 

More from kunj desai (10)

OLAP operations
OLAP operationsOLAP operations
OLAP operations
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkers
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Introduction to 8085 microprocessor
Introduction to 8085 microprocessorIntroduction to 8085 microprocessor
Introduction to 8085 microprocessor
 
Custom Controls in ASP.net
Custom Controls in ASP.netCustom Controls in ASP.net
Custom Controls in ASP.net
 
Requirement specification (SRS)
Requirement specification (SRS)Requirement specification (SRS)
Requirement specification (SRS)
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
php databse handling
php databse handlingphp databse handling
php databse handling
 
Concept of constructors
Concept of constructorsConcept of constructors
Concept of constructors
 

Recently uploaded

VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 

Recently uploaded (20)

VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 

JDBC Connectivity Model

  • 1. JDBC Connectivity Model • Name: Kunj Desai • Enrollment No.: 140950107022 • Branch : CSE-A • Year:2017
  • 2. Java and the database • Database is used to store data. It is also known as persistent storage as the data is stored and can be retrieved anytime. • Java and database are used almost everywhere to store persistent data and retrieve it when required.
  • 3. SQL • Information stored in the database is in tables and the language used to query information from the database is SQL. • Using SQL we can query a table based on the requirement.
  • 4. DDL – DML – DCL - TCL • DDL – Data Definition Language – These queries are used to create database objects such as tables, indexes, procedures, constraints – Create , drop, alter,truncate,comment,rename • DML – Data Manipulation Language – These queries are used to manipulate the data in the database tables. – Insert, update, delete, select (more available) • DCL – Data Control Language – These are data control queries like grant and revoke permissions • TCL– Transaction Control Language – These are transaction control queries like commit, revoke, savepoint, set transaction
  • 5. What is JDBC? • JDBC provides Java applications with access to most database systems via SQL • The architecture and API closely resemble Microsoft's ODBC • JDBC 1.0 was originally introduced into Java 1.1 – JDBC 2.0 was added to Java 1.2 • JDBC is based on SQL-92 • JDBC classes are contained within the java.sql package – There are few classes – There are several interfaces
  • 6. Database Connectivity History Before APIs like JDBC and ODBC, database connectivity was tedious • Each database vendor provided a function library for accessing their database • The connectivity library was proprietary. • If the database vendor changed for the application, the data access portions had to be rewritten • If the application was poorly structured, rewriting its data access might involve rewriting the majority of the application • The costs incurred generally meant that application developers were stuck with a particular database product for a given application
  • 7. JDBC Architecture • With JDBC, the application programmer uses the JDBC API – The developer never uses any proprietary APIs • Any proprietary APIs are implemented by a JDBC driver • There are 4 types of JDBC Drivers Java Application JDBC API JDBC DriverManager JDBC Driver JDBC Driver
  • 8. JDBC Drivers • Type 1 Driver - JDBC-ODBC bridge – This is an ODBC driver, which is open source • Type 2 Driver – Native API driver – This is more like the OCI (Oracle Call Interface) call interface is converted to native calls of the database. • Type 3 Driver – Network protocol driver – This is achieved by using a Java Driver in a middleware • Type 4 Driver – Native Protocol Driver – This is a driver written purely in Java Language • We Usually prefer to depend on the Type 4 driver – Eg: Oracle thin driver
  • 9. Java-Oracle Example public void ConnectToAndQueryDatabase (String username, String password) { Connection con = DriverManager.getConnection( "jdbc:myD river:myDatabase", username, password); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1"); while (rs.next()) { int x = rs.getInt("a"); String s = rs.getString("b"); float f = rs.getFloat("c"); } } •In the example we have a method call ConnectTo And QueryDatabase which takes in a username, password •The Connection Interface creates a connection. A connection is created by using the DriverManager Class with the connection string , username, password. The concrete implementation is OracleConnection. •The statement Interface creates a statement. The concrete implementation is Oracle Statement. •ResultSet stores the result after invoking execute Query on the statement object. We can iterate over the resultset to get the results from table.
  • 10. Statement and Prepared Statement • A Statement Interface is used to create a statement i.e. a query to be executed against a database. In this process, two calls are made to the database system , one to get the table metadata and other to get the data itself. The statement object is also compiled every time it executes. • A Prepared statement comes in handy as it is compiled and cached and only makes on database call when invoked. The compilation would be skipped even if the values in the where clause change
  • 11. Statement and Prepared Statement• Statement Statement stmt= con.statment(“select * from mytab where num=22”); • Prepared Statement PreparedStatement pstmt = con.preparestatement(select * from mytab where num=?”); pstmt.setInt(1,”11”); This sets the value of ? as 11 – If we run the statement in for loop every time changing the where clause, the statement is compiled every time before execution. – In the case of prepared statement , the prepared statement is cached and compiled only one time in the event of a for loop with changing where clause.
  • 12. Stored Procedures • Stored procedures are compiled sql programs which are stored in the database system and can be executed in the database. • We use the call keyword in SQL to execute stored procedures • Java can access the stored procedures in the database by using the Callable statements
  • 13. Callable Statements • Callable statements are used to call stored procedures in the database. CallableStatement cstmt = null; try { String SQL = "{call myprocedure(?, ?)}"; //? Can be set dynamically as in prepared statement cstmt = conn.prepareCall (SQL); . . . } catch (SQLException e) { . . . } finally { . . . }
  • 14. JDBC Interfaces • ResultSet – Represents the result of an SQL statement – Provides methods for navigating through the resulting data • DatabaseMetaData – Provides access to a database's system catalogue • ResultSetMetaData – Provides information about the data contained within a ResultSet
  • 15. Transactions • Transactions imply a situation when we have one or more SQL statements to be committed only when everything goes right – Assume we have 10 databases which are always to be in sync. So we would have one sql query to be executed across all databases. So, the sql query should committed in all the databases only after successful execution in all 10 databases. This is called a transaction. The transaction is committed only after successful execution across all databases.
  • 16. Closing Connections • Always remember to close in the following sequence. – Resultset – Statement/Prepared Statement – Connections • Do a null check always before closing the connections using close() method.