The document describes Java Database Connectivity (JDBC), which provides Java applications with access to most database systems via SQL. It outlines the JDBC architecture and classes in the java.sql package. JDBC drivers allow applications to connect to databases without using proprietary APIs. There are four types of JDBC drivers. The document also provides an example of how to load a driver, connect to a database, execute a query, and retrieve and display results.
Java applications cannot directly communicate with a database to submit data and retrieve the results of queries.
This is because a database can interpret only SQL statements and not Java language statements.
For this reason, you need a mechanism to translate Java statements into SQL statements.
The JDBC architecture provides the mechanism for this kind of translation.
The JDBC architecture can be classified into two layers :
JDBC application layer.
JDBC driver layer.
JDBC application layer : Signifies a Java application that uses the JDBC API to interact with the JDBC drivers. A JDBC driver is software that a Java application uses to access a database. The JDBC driver manager of JDBC API connects the Java application to the driver.
JDBC driver layer : Acts as an interface between a Java applications and a database. This layer contains a driver , such as a SQL server driver or an Oracle driver , which enables connectivity to a database.
A driver sends the request of a Java application to the database. After processing the request, the database sends the response back to the driver. The driver translates and sends the response to the JDBC API. The JDBC API forwards it to the Java application.
JDBC tutorial with full example, including CRUD sql statement with JDBC Statement and PreparedStatement, interact Stored Procedure with CallableStatement, JDBC transaction
Java to database connectivity for beginners, Introduction to JDBC, Getting Started with java database programming, What is java database?, core java, java to standard edition, core java, java
Java applications cannot directly communicate with a database to submit data and retrieve the results of queries.
This is because a database can interpret only SQL statements and not Java language statements.
For this reason, you need a mechanism to translate Java statements into SQL statements.
The JDBC architecture provides the mechanism for this kind of translation.
The JDBC architecture can be classified into two layers :
JDBC application layer.
JDBC driver layer.
JDBC application layer : Signifies a Java application that uses the JDBC API to interact with the JDBC drivers. A JDBC driver is software that a Java application uses to access a database. The JDBC driver manager of JDBC API connects the Java application to the driver.
JDBC driver layer : Acts as an interface between a Java applications and a database. This layer contains a driver , such as a SQL server driver or an Oracle driver , which enables connectivity to a database.
A driver sends the request of a Java application to the database. After processing the request, the database sends the response back to the driver. The driver translates and sends the response to the JDBC API. The JDBC API forwards it to the Java application.
JDBC tutorial with full example, including CRUD sql statement with JDBC Statement and PreparedStatement, interact Stored Procedure with CallableStatement, JDBC transaction
Java to database connectivity for beginners, Introduction to JDBC, Getting Started with java database programming, What is java database?, core java, java to standard edition, core java, java
Java DataBase Connectivity API (JDBC API)Luzan Baral
JDBC is a Java-based data access technology (Java Standard Edition platform) from Oracle Corporation. This technology is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases. A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source in the JVM host environment.
This slide is special for master students (MIBS & MIFB) in UUM. Also useful for readers who are interested in the topic of contemporary Islamic banking.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
2. JDBC - Java Database Connectivity
The objectives of this chapter are:
To describe the architecture of JDBC
To outline the classes in the java.sql package
To understand the use of JDBC
3. 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
4. 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
5. 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
6. JDBC Drivers
There are 4 types of JDBC Drivers
Type 1 - JDBC-ODBC Bridge
Type 2 - JDBC-Native Bridge
Type 3 - JDBC-Net Bridge
Type 4 - Direct JDBC Driver
Type 1 only runs on platforms where ODBC is available
ODBC must be configured separately
Type 2 Drivers map between a proprietary Database API and
the JDBC API
Type 3 Drivers are used with middleware products
Type 4 Drivers are written in Java
In most cases, type 4 drivers are preferred
7. JDBC Classes
DriverManager
Manages JDBC Drivers
Used to Obtain a connection to a Database
• Types
Defines constants which identify SQL types
Date
Used to Map between java.util.Date and the SQL DATE type
• Time
Used to Map between java.util.Date and the SQL TIME type
TimeStamp
Used to Map between java.util.Date and the SQL TIMESTAMP type
8. JDBC Interfaces
Driver
All JDBC Drivers must implement the Driver interface. Used to
obtain a connection to a specific database type
• Connection
Represents a connection to a specific database
Used for creating statements
Used for managing database transactions
Used for accessing stored procedures
Used for creating callable statements
Statement
Used for executing SQL statements against the database
9. JDBC Interfaces
ResultSet
Represents the result of an SQL statement
Provides methods for navigating through the resulting data
• PreparedStatement
Similar to a stored procedure
An SQL statement (which can contain parameters) is compiled and stored in
the database
CallableStatement
Used for executing stored procedures
DatabaseMetaData
Provides access to a database's system catalogue
ResultSetMetaData
Provides information about the data contained within a ResultSet
10. Using JDBC
To execute a statement against a database, the following
flow is observed
Load the driver (Only performed once)
Obtain a Connection to the database (Save for later use)
Obtain a Statement object from the Connection
Use the Statement object to execute SQL. Updates, inserts and
deletes return Boolean. Selects return a ResultSet
Navigate ResultSet, using data as required
Close ResultSet
Close Statement
• Do NOT close the connection
The same connection object can be used to create further statements
A Connection may only have one active Statement at a time. Do not
forget to close the statement when it is no longer needed.
Close the connection when you no longer need to access the database
11. Loading Drivers
Even a good API can have problems
Loading drivers fits into this category
The DriverManager is a singleton
Each JDBC Driver is also a singleton
When a JDBC Driver class is loaded, it must create an instance of
itself and register that instance with the JDBC DriverManager
How does one load a "class" into the Virtual machine?
Use the static method Class.forName()
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
12. Connecting to a Database
Once a Driver is loaded, a connection can be made to the database
The connection is defined by URL
The URL has the following form:
jdbc:driver:databasename
• Examples:
jdbc:odbc:MyOdbcDatabase
jdbc:postgres:WebsiteDatabase
jdbc:oracle:CustomerInfo
A connection is obtained in the following manner:
Connection aConnection = DriverManager.getConnection("jdbc:odbc:myDatabase");
• Overloaded versions of the getConnection method allow the
specification of a username and password for authentication with the
database.
13. Using a Connection
The Connection interface defines many methods for
managing and using a connection to the database
public Statement createStatement()
public PreparedStatement prepareStatement(String sql)
public void setAutoCommit(boolean)
public void commit()
public void rollback()
public void close()
• The most commonly used method is createStatement()
When an SQL statement is to be issued against the database, a
Statement object must be created through the Connection
14. Using a Statement
The Statement interface defines two methods for
executing SQL against the database
public ResultSet executeQuery(String sql)
public int executeUpdate(String sql)
• executeQuery returns a ResultSet
• All rows and columns which match the query are contained within the
ResultSet
• The developer navigates through the ResultSet and uses the data as
required.
• executeUpdate returns the number of rows changed by
the update statement
This is used for insert statements, update statements and delete
statements
15. Using a ResultSet
The ResultSet interface defines many navigation methods
public boolean first()
public boolean last()
public boolean next()
public boolean previous()
The ResultSet interface also defines data access methods
public int getInt(int columnNumber) -- Note: Columns are numbered
public int getInt(String columnName) -- from 1 (not 0)
public long getLong(int columnNumber)
public long getLong(String columnName)
public String getString(int columnNumber)
public String getString(String columnName)
There are MANY more methods. Check the API
documentation for a complete list
16. SQL Types/Java Types Mapping
SQL Type Java Type
CHAR String
VARCHAR String
LONGVARCHAR String
NUMERIC java.Math.BigDecimal
DECIMAL java.Math.BigDecimal
BIT boolean
TINYINT int
SMALLINT int
INTEGER int
BIGINT long
REAL float
FLOAT double
DOUBLE double
BINARY byte[]
VARBINARY byte[]
DATE java.sql.Date
TIME java.sql.Time
TIMESTAMP java.sql.Timestamp