SlideShare a Scribd company logo
Database System Sunita M. Dol
Page 1
HANDOUT#10
Aim:
Write a java program for database connectivity using JDBC.
Theory:
Java JDBC
Java JDBC is a java API to connect and execute query with the database. JDBC API uses jdbc
drivers to connect with the database.
Why to use JDBC?
Before JDBC, ODBC API was the database API to connect and execute query with the database.
But, ODBC API uses ODBC driver which is written in C language (i.e. platform dependent and
unsecured). That is why Java has defined its own API (JDBC API) that uses JDBC drivers
(written in Java language).
What is JDBC?
JDBC stands for Java Database Connectivity, which is a standard Java API for database-
independent connectivity between the Java programming language and a wide range of
databases.
The JDBC library includes APIs for each of the tasks mentioned below that are commonly
associated with database usage.
1. Making a connection to a database.
2. Creating SQL or MySQL statements.
3. Executing SQL or MySQL queries in the database.
4. Viewing & Modifying the resulting records.
Common JDBC Components
Database System Sunita M. Dol
Page 2
The JDBC API provides the following interfaces and classes −
• DriverManager: This class manages a list of database drivers. Matches connection
request from the java application with the proper database driver using communication
sub protocol. The first driver that recognizes a certain subprotocol under JDBC will be
used to establish a database Connection.
• Driver: This interface handles the communications with the database server. You will
interact directly with Driver objects very rarely. Instead, you use DriverManager objects,
which manage objects of this type. It also abstracts the details associated with working
with Driver objects.
• Connection: This interface with all methods for contacting a database. The connection
object represents communication context, i.e., all communication with database is
through connection object only.
• Statement: You use objects created from this interface to submit the SQL statements to
the database. Some derived interfaces accept parameters in addition to executing stored
procedures.
• ResultSet: These objects hold data retrieved from a database after you execute an SQL
query using Statement objects. It acts as an integrator to allow you to move through its
data.
• SQLException: This class handles any errors that occur in a database application.
CreatingJDBCApplication
There are following six steps involved in building a JDBC application −
• Import the packages: Requires that you include the packages containing the JDBC
classes needed for database programming. Most often, using import java.sql.* will
suffice.
• Register the JDBC driver: Requires that you initialize a driver so you can open a
communication channel with the database.
• Open a connection: Requires using the DriverManager.getConnection() method to
create a Connection object, which represents a physical connection with the database.
• Execute a query: Requires using an object of type Statement for building and
submitting an SQL statement to the database.
• Extract data from result set: Requires that you use the
appropriate ResultSet.getXXX() method to retrieve the data from the result set.
• Clean up the environment: Requires explicitly closing all database resources versus
relying on the JVM's garbage collection.
Program:
Input and Output:
Database System Sunita M. Dol
Page 3
Conclusion:
Java JDBC is a java API to connect and execute query with the database. We have written a java
program for database connectivity using JDBC which performed the following action:
• Insert
• Search
• Delete
• Modify
References:
• Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) sixth edition.
• Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) fifth edition.
• http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/
• http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/
• http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/
• https://www.tutorialspoint.com/jdbc/jdbc-introduction.htm

More Related Content

PDF
Overview Of JDBC
PPTX
Java DataBase Connectivity API (JDBC API)
PDF
Database and Java Database Connectivity
PPT
Java database connectivity
PPT
Jdbc (database in java)
PPTX
PDF
Jdbc connectivity in java
Overview Of JDBC
Java DataBase Connectivity API (JDBC API)
Database and Java Database Connectivity
Java database connectivity
Jdbc (database in java)
Jdbc connectivity in java

What's hot (19)

PPTX
java Jdbc
PPTX
Jdbc_ravi_2016
PPT
PDF
jdbc
PPTX
Java database connectivity with MySql
PPTX
PPT
JDBC Connectivity Model
PPT
Jdbc complete
PPT
PPT
java jdbc connection
PPTX
DataBase Connectivity
PPTX
JDBC ppt
PPTX
1. java database connectivity (jdbc)
PPTX
Lecture 1. java database connectivity
PPTX
Java database connectivity
PPT
Jdbc slide for beginers
java Jdbc
Jdbc_ravi_2016
jdbc
Java database connectivity with MySql
JDBC Connectivity Model
Jdbc complete
java jdbc connection
DataBase Connectivity
JDBC ppt
1. java database connectivity (jdbc)
Lecture 1. java database connectivity
Java database connectivity
Jdbc slide for beginers
Ad

Similar to Assignment#10 (20)

PDF
IRJET- Review on Java Database Connectivity
PPT
JDBC java for learning java for learn.ppt
PDF
Chapter 5 JDBC.pdf for stufent of computer andtudent It s
PPTX
Java Database Connectivity(JDBC) java database
DOC
jdbc document
PPT
4-INTERDUCATION TO JDBC-2019.ppt
PDF
JDBC-Introduction
PDF
Java Database Connectivity (Advanced programming)
PPT
Java database connectivity
PPT
JDBC.ppt
PPTX
Java Database Connectivity (JDBC)
PPT
Java Database Connectivity
PPTX
java 4 Part 1 computer science.pptx
PPT
Jdbc sasidhar
PPT
Chap3 3 12
PDF
JDBC Presentation with JAVA code Examples.pdf
PPTX
Jdbc introduction
PPTX
Java database connectivity with MySql
PPTX
Core jdbc basics
DOC
Java database programming with jdbc
IRJET- Review on Java Database Connectivity
JDBC java for learning java for learn.ppt
Chapter 5 JDBC.pdf for stufent of computer andtudent It s
Java Database Connectivity(JDBC) java database
jdbc document
4-INTERDUCATION TO JDBC-2019.ppt
JDBC-Introduction
Java Database Connectivity (Advanced programming)
Java database connectivity
JDBC.ppt
Java Database Connectivity (JDBC)
Java Database Connectivity
java 4 Part 1 computer science.pptx
Jdbc sasidhar
Chap3 3 12
JDBC Presentation with JAVA code Examples.pdf
Jdbc introduction
Java database connectivity with MySql
Core jdbc basics
Java database programming with jdbc
Ad

More from Sunita Milind Dol (20)

PDF
Assignment No. 10 on Unit-IV Set Theory, Relations and Function
PDF
Assignment No. 9 on Unit-IV Set Theory, Relations and Function
PDF
Assignment No. 8 on Unit-IV Set Theory, Relations and Function
PDF
Assignment No. 7 on Unit-IV - Set Theory, Relations and Function
PDF
Assignment No. 6 on Representation of Expression
PDF
Assignment No. 5 on Unit-III Representation of Expression
PDF
Assignment No. 4 on Unit-II Mathematical Logic
PDF
Assignment No. 3 on Unit-II Mathematical Logic
PDF
Assignment No. 2 on Unit-I Mathematical Induction
PDF
Assignment No. 1 on Unit-I Fundamental Principles of Counting
PDF
Unit Number 5 - Research Ethics, IPR and Publishing
PDF
Unit Number 4 - Research reports and Thesis writing
PDF
Unit Number 3 - Data collection and Statistical Analysis
PDF
Unit Number 2 - Research Problem Formulation and Methods
PDF
Unit Number 1 - Introduction to Research
PDF
Unit Number 5 - Research Ethics, IPR and Publishing
PDF
Unit Number 5 - Research reports and Thesis writing
PDF
Unit Number 3 - Data collection and Statistical Analysis
PDF
Unit Number 2 - Research Problem Formulation and Methods
PDF
Unit Number 1 : Introduction to Research
Assignment No. 10 on Unit-IV Set Theory, Relations and Function
Assignment No. 9 on Unit-IV Set Theory, Relations and Function
Assignment No. 8 on Unit-IV Set Theory, Relations and Function
Assignment No. 7 on Unit-IV - Set Theory, Relations and Function
Assignment No. 6 on Representation of Expression
Assignment No. 5 on Unit-III Representation of Expression
Assignment No. 4 on Unit-II Mathematical Logic
Assignment No. 3 on Unit-II Mathematical Logic
Assignment No. 2 on Unit-I Mathematical Induction
Assignment No. 1 on Unit-I Fundamental Principles of Counting
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 4 - Research reports and Thesis writing
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 1 - Introduction to Research
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research reports and Thesis writing
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 1 : Introduction to Research

Recently uploaded (20)

PPTX
Artificial Intelligence
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Geodesy 1.pptx...............................................
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT
Total quality management ppt for engineering students
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
737-MAX_SRG.pdf student reference guides
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PPT
Mechanical Engineering MATERIALS Selection
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
Artificial Intelligence
Safety Seminar civil to be ensured for safe working.
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Foundation to blockchain - A guide to Blockchain Tech
III.4.1.2_The_Space_Environment.p pdffdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Geodesy 1.pptx...............................................
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Total quality management ppt for engineering students
CYBER-CRIMES AND SECURITY A guide to understanding
737-MAX_SRG.pdf student reference guides
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Internet of Things (IOT) - A guide to understanding
Mechanical Engineering MATERIALS Selection
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Embodied AI: Ushering in the Next Era of Intelligent Systems

Assignment#10

  • 1. Database System Sunita M. Dol Page 1 HANDOUT#10 Aim: Write a java program for database connectivity using JDBC. Theory: Java JDBC Java JDBC is a java API to connect and execute query with the database. JDBC API uses jdbc drivers to connect with the database. Why to use JDBC? Before JDBC, ODBC API was the database API to connect and execute query with the database. But, ODBC API uses ODBC driver which is written in C language (i.e. platform dependent and unsecured). That is why Java has defined its own API (JDBC API) that uses JDBC drivers (written in Java language). What is JDBC? JDBC stands for Java Database Connectivity, which is a standard Java API for database- independent connectivity between the Java programming language and a wide range of databases. The JDBC library includes APIs for each of the tasks mentioned below that are commonly associated with database usage. 1. Making a connection to a database. 2. Creating SQL or MySQL statements. 3. Executing SQL or MySQL queries in the database. 4. Viewing & Modifying the resulting records. Common JDBC Components
  • 2. Database System Sunita M. Dol Page 2 The JDBC API provides the following interfaces and classes − • DriverManager: This class manages a list of database drivers. Matches connection request from the java application with the proper database driver using communication sub protocol. The first driver that recognizes a certain subprotocol under JDBC will be used to establish a database Connection. • Driver: This interface handles the communications with the database server. You will interact directly with Driver objects very rarely. Instead, you use DriverManager objects, which manage objects of this type. It also abstracts the details associated with working with Driver objects. • Connection: This interface with all methods for contacting a database. The connection object represents communication context, i.e., all communication with database is through connection object only. • Statement: You use objects created from this interface to submit the SQL statements to the database. Some derived interfaces accept parameters in addition to executing stored procedures. • ResultSet: These objects hold data retrieved from a database after you execute an SQL query using Statement objects. It acts as an integrator to allow you to move through its data. • SQLException: This class handles any errors that occur in a database application. CreatingJDBCApplication There are following six steps involved in building a JDBC application − • Import the packages: Requires that you include the packages containing the JDBC classes needed for database programming. Most often, using import java.sql.* will suffice. • Register the JDBC driver: Requires that you initialize a driver so you can open a communication channel with the database. • Open a connection: Requires using the DriverManager.getConnection() method to create a Connection object, which represents a physical connection with the database. • Execute a query: Requires using an object of type Statement for building and submitting an SQL statement to the database. • Extract data from result set: Requires that you use the appropriate ResultSet.getXXX() method to retrieve the data from the result set. • Clean up the environment: Requires explicitly closing all database resources versus relying on the JVM's garbage collection. Program: Input and Output:
  • 3. Database System Sunita M. Dol Page 3 Conclusion: Java JDBC is a java API to connect and execute query with the database. We have written a java program for database connectivity using JDBC which performed the following action: • Insert • Search • Delete • Modify References: • Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) sixth edition. • Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) fifth edition. • http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/ • http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/ • http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/ • https://www.tutorialspoint.com/jdbc/jdbc-introduction.htm