















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to java database connectivity (jdbc) api and its role in vendor-independent database connectivity. It covers the importance of jdbc api, the role of drivers, and the different types of jdbc drivers. It also discusses the merits and demerits of using jdbc api and the java application process for database access.
Typology: Slides
1 / 23
This page cannot be seen from the preview
Don't miss anything!
Java
An Introduction
Java Short Course Day-
Docsity.com
Java
o Java Database Connectivity
Concepts JDBC API Data Base Connectivity using Java Important Features of JDBC API
Docsity.com
Java
o Role of Driver
JDBC API talks with vendor specific driver Driver converts JDBC API calls to vendor specific Database API calls
o Merits and Demerits Applications using JDBC API have no access to vendor specific Database API but to driver only The performance is reduced The same application can be used with another implementation of the same database for any other vendor for which a driver is available
Docsity.com
Java
o sdfsd
Docsity.com
Java
Java application Data source
JDBC API (^) JDBC-ODBC Bridge ODBC API (^) ODBC Layer
application process
ODBC process
CCTM: Course material developed by James King (james.king@londonmet.ac.uk Docsity.com )
Java
Java application Data source
JDBC API
JDBC Driver (part Java, part native code)
Vendor-specific API
application process
CCTM: Course material developed by James King (james.king@londonmet.ac.uk Docsity.com )
Java
network
Java application Data source
JDBC API (^) JDBC Driver
application process
CCTM: Course material developed by James King (james.king@londonmet.ac.uk Docsity.com )
Java
JDBC Driver Manager
ODBC Oracle Driver XYZ Driver
Access Oracle xyzBase CCTM: Course material developed by James King (james.king@londonmet.ac.uk Docsity.com )
Java
1. Load Driver. The forName method of Class loads the specified JDBC
driver and initialises the DriverManager.
2. Connect to database. getConnection in DriverManager returns a
Connection Object. The Connection Object is used to communicate with the database specified in getConnection.
3. Execute SQL. createStatement in Connection returns an Statement
Object which can be used to send SQL statements to the connected database.
search or modify the database. (Searches produce a ResultSet object)
5. Process the ResultSet or handle any errors 6. Close Statement object and close the Connection when you have no
more statements to send.
CCTM: Course material developed by James King (james.king@londonmet.ac.uk Docsity.com )
Java
DriverManager getConnection
Connection createStatement
Statement
Class forName
CCTM: Course material developed by James King (james.king@londonmet.ac.uk)
Class.forName loads the DriverManager
DriverManager. getconnection connects to a database and returns a Connection object
Connection. createStatement provides a Statement object you can insert SQL into
Docsity.com
Java
o A JDBC driver is always needed to connect to a database
o Loading a driver requires the class name of the driver. For
JDBC-ODBC: sun.jdbc.odbc.JdbcOdbcDriver Oracle driver: oracle.jdbc.driver.OracleDriver mySQL: org.gjt.mm.mysql.Driver
o The class for the name of the driver is loaded using the static
Class.forName("org.gjt.mm.mysql.Driver"); This loads and initialises the driver. It is possible to load several drivers.
Docsity.com
Java
Subname: indicates the location and name of the database to be accessed. Syntax is driver specific
Sub-protocol: identifies a database driver
Protocol: JDBC is the only protocol in JDBC
Step 2: Connecting to a Database part 1
A JDBC URL represents a driver and has following three-part syntax jdbc:
"jdbc:mysql://www3.unl.ac.uk:3306/kingj1”
CCTM: Course material developed by James King (james.king@londonmet.ac.uk Docsity.com )
Java
CCTM: Course material developed by James King (james.king@londonmet.ac.uk Docsity.com )
Java
Step 4: Executing SQL (Modifying the Database)
Number of records effected. In this example SQL statement surrounded by " " should be 1 since we are adding a single record
CCTM: Course material developed by James King (james.king@londonmet.ac.uk Docsity.com )