Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java...
-
Upload
alicia-martin -
Category
Documents
-
view
244 -
download
4
Transcript of Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java...
![Page 1: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/1.jpg)
Java Database Connectivity (JDBC)
![Page 2: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/2.jpg)
Introduction to JDBC• JDBC is a simple API for connecting from Java applications to multiple
databases.
• Lets you smoothly translate between the world of the database, and the world of the Java application.
• The idea of a universal database access API is not a new one. – For example, Open Database Connectivity (ODBC) was developed to create a single
standard for database access in the Windows environment.
• JDBC API aims to be as simple as possible while providing developers with maximum flexibility.
![Page 3: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/3.jpg)
Understanding JDBC Drivers• To connect to a database
– , you first need a JDBC Driver.
• JDBC Driver: – set of classes that interface
with a specific database engine.
Java Application
JDBC Driver Manager
JDBC-ODBC Bridge
VendorSpecific
JDBC Driver
VendorSpecific
ODBC Driver
Database
Database
Diagram Source: Marty Hall,Core Web Programming(Prentice Hall.)
![Page 4: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/4.jpg)
JDBC Drivers
• JDBC drivers exist for every major database including: – Oracle, SQL Server, Sybase, and MySQL.
• We will use MSAccess Data base,Microsoft’s ODBC driver,Sun’s JDBC-ODBC bridge.
![Page 5: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/5.jpg)
Java Program uses JDBC API
ODBC Data Source
JDBC-ODBC bridge converts these calls to ODBC
Your tables in MSAcess
}do
manually
}do in
pgm
![Page 6: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/6.jpg)
java.sql• The package comprising the core JDBC API is called
java.sql
• We use a simple MS Access database, which means that the inbuilt JDBC-ODBC bridge driver can be employed
• If you wish to experiment with other databases, place
the appropriate JDBC driver within folder java\jre\lib\
ext.
![Page 7: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/7.jpg)
Creating an ODBC Data Source
![Page 8: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/8.jpg)
Creating an ODBC Data Source
1. First , it is necessary to register the database as an
ODBC Data Source.
2. Once this has been done, the database can be
referred to by its Data Source Name (DSN).
![Page 9: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/9.jpg)
steps to set up your own ODBC Data Source(only for ODBC databases!)
![Page 10: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/10.jpg)
Simple Database Access
![Page 11: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/11.jpg)
Using JDBC to access a database requires several steps
![Page 12: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/12.jpg)
Using JDBC to access a database requires several steps
1.Load the Database Driver
• class is used to hold methods that operate upon other
classes in order to furnish details of their characteristics
• forName method of class
![Page 13: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/13.jpg)
Using JDBC to access a database requires several steps
2. Establish a Connection to the Database
• declare a Connection reference
• call static method getConnection of class DriverManager to
return a Connection object
• Method getConnection takes three String arguments:1. a URL-style address for the database;2. a user name;3. a password.
![Page 14: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/14.jpg)
Using JDBC to access a database requires several steps
2. Establish a Connection to the DatabaseAddress format: jdbc:<sub-protocol>:<data-source>
• <sub-protocol> specifies a database connection service
(i.e., a driver)
• <data-source> provides all the information needed
by the service to locate the database
![Page 15: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/15.jpg)
Using JDBC to access a database requires several steps
2. Establish a Connection to the Database
Assuming that our Finances database is indeed local and that we
did not set a user name or password for this database
If this same database were remote
![Page 16: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/16.jpg)
Using JDBC to access a database requires several steps
3. Create a Statement Object and Store its Reference
• Call createStatement () method of our Connection object
• Save the address of the object returned in a Statement
reference.
![Page 17: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/17.jpg)
Using JDBC to access a database requires several steps
4. Run a Query/Update and Accept the Result(s)
• Class Statement has methods to execute queries:
1. executeQuery () to retrieve data from a database
2. executeUpdate() to change the contents of the
database• The former method returns a ResultSet object,
• latter returns an integer that indicates the number of database
rows that have been affected by the updating operation.
![Page 18: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/18.jpg)
Using JDBC to access a database requires several steps
4. Run a Query/Update and Accept the Result(s)
![Page 19: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/19.jpg)
Using JDBC to access a database requires several steps
4. Run a Query/Update and Accept the Result(s)
![Page 20: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/20.jpg)
Using JDBC to access a database requires several steps
5. Manipulate/Display/Check Result(s)
• The only method of ResultSet that we need to make use of at
present is next, which moves the ResultSet cursor/pointer to
the next row in the set of rows referred to by that object.
• We can retrieve data via either the field name or the field
position using the appropriate getXXX () method
![Page 21: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/21.jpg)
5. Manipulate/Display/Check Result(s)
![Page 22: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/22.jpg)
5. Manipulate/Display/Check Result(s)
6. Repeat Steps 4 and 5 as Required
7.Close the Connection
![Page 23: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/23.jpg)
![Page 24: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/24.jpg)
![Page 25: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/25.jpg)
![Page 26: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/26.jpg)
![Page 27: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/27.jpg)
![Page 28: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/28.jpg)
![Page 29: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/29.jpg)
![Page 30: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/30.jpg)
Modifying the Database Contents
![Page 31: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/31.jpg)
• Database Update Statements : • INSERT• DELETE• UPDATE
• Update statements are submitted via the
executeUpdate() method of statement
interface
Modifying the Database Contents
![Page 32: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/32.jpg)
Modifying the Database Contents
![Page 33: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/33.jpg)
Example:
![Page 34: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/34.jpg)
Example:
![Page 35: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/35.jpg)
Example:
![Page 36: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/36.jpg)
Example:
![Page 37: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/37.jpg)
Example:
![Page 38: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/38.jpg)
Example:
![Page 39: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/39.jpg)
Example:
![Page 40: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/40.jpg)
Transactions
![Page 41: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/41.jpg)
Transactions• one or more SQL statements that may be grouped together as a
single processing entity
• We want either all the statements or none of them to be
executed.
• Java provides the Connection interface methods
1. commit used at the end of a transaction to
commit/finalise the database changes
2. rollback used to restore the database to the state
it was in prior to the current transaction
![Page 42: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/42.jpg)
Transactions• By default, JDBC automatically commits each individual SQL
statement that is applied to a database.
• In order to change this default behaviour so that transaction
processing may be carried out, we must first execute Connection
method setAutoCommit with an argument of false
• We can then use methods commit and rollback to effect
transaction processing.
![Page 43: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/43.jpg)
Transactions
![Page 44: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/44.jpg)
Meta Data
![Page 45: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/45.jpg)
Meta Data
• 'data about data‘
• Two categories of meta data available through the
JDBC API:• data about the rows and columns returned by a query (i.e.,
data about ResultSet objects);
• data about the database as a whole.
The first of these is provided by interface ResultSetMetaData, an
object of which is returned by the ResultSet method getMetaData
![Page 46: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/46.jpg)
Meta Data
• data about the rows and columns is provided by interface
ResultSetMetaData, an object of which is returned by the
ResultSet method getMetaData
• Data about the database as a whole is provided by interface
DatabaseMetaData, an object of which is returned by the
Connection method getMetaData
![Page 47: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/47.jpg)
Meta Data
• Information available from a ResultSetMetaData
object includes the following:• the number of fields/columns in a ResultSet object;
• the name of a specified field;
• the data type of a field;
• the maximum width of a field;
• the table to which a field belongs.
![Page 48: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/48.jpg)
Meta Data
• SQL types is represented in class java.sql.Types
INTEGER and VARCHAR are particularly commonplace, the latter
of these corresponding to string values.
![Page 49: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/49.jpg)
Meta Data
• The example coming up makes use of the following
ResultSetMetaData methods, which return properties
of the database fields held in a ResultSetMetaData
object.
![Page 50: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/50.jpg)
Meta Data
![Page 51: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/51.jpg)
Meta Data
![Page 52: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/52.jpg)
Meta Data
![Page 53: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/53.jpg)
Meta Data
![Page 54: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/54.jpg)
Meta Data
![Page 55: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/55.jpg)
Meta Data
![Page 56: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/56.jpg)
Meta Data
![Page 57: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/57.jpg)
Meta Data
![Page 58: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/58.jpg)
![Page 59: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/59.jpg)
Scrollable ResultSets in JDBC 2
![Page 60: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/60.jpg)
Scrollable ResultSets in JDBC 2
With the emergence of JDBC 2 in Java 2, however, a great deal more
flexibility was made available to Java programmers by the
introduction of the following ResultSet methods:
![Page 61: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/61.jpg)
Scrollable ResultSets in JDBC 2
• results.relative(-3); //Move back 3 rows.
• results.absolute(3); // Move to row 3 (from start of
ResultSet).
• An overloaded form of the Connection method createStatement
is used to create scrollable ResultSets. This method that takes
two integer arguments.
![Page 62: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/62.jpg)
Scrollable ResultSets in JDBC 2
• There are three possible values that
<resultSetType> can take:
• TYPE_SCROLL_SENSITIVE causes any changes made to the data
rows to be reflected dynamically in the ResultSet object, while
TYPE_SCROLL_INSENSITIVE does not.
![Page 63: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/63.jpg)
Scrollable ResultSets in JDBC 2
• <resultSetConcurrency> can take two possible
values
the first means that we cannot make changes to the
ResultSet rows, while the second will allow changes to
be made
![Page 64: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/64.jpg)
Scrollable ResultSets in JDBC 2
![Page 65: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/65.jpg)
Scrollable ResultSets in JDBC 2
![Page 66: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/66.jpg)
Scrollable ResultSets in JDBC 2
![Page 67: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/67.jpg)
Scrollable ResultSets in JDBC 2
![Page 68: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/68.jpg)
Scrollable ResultSets in JDBC 2
![Page 69: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/69.jpg)
Scrollable ResultSets in JDBC 2
![Page 70: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/70.jpg)
Scrollable ResultSets in JDBC 2
![Page 71: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/71.jpg)
Scrollable ResultSets in JDBC 2
![Page 72: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/72.jpg)
Modifying Databases via Java
Methods
![Page 73: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/73.jpg)
Modifying Databases via Java Methods
• With of JDBC 2 we can modify ResultSet rows directly via Java
methods
• Without having to send SQL statements
• the changes reflected in the database itself!
To do this:
1. use the second version of createStatement
2. supply ResultSet.CONCUR_UPDATABLE as the second
argument.
![Page 74: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/74.jpg)
Modifying Databases via Java Methods
• The updateable ResultSet object does not have to be
scrollable
![Page 75: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/75.jpg)
Modifying Databases via Java Methods
• A set of updateXXX methods are used to update database.
• Each of these methods takes two arguments:
• a string specifying the name of the field to be
updated;
• a value of the appropriate type that is to be
assigned to the field
![Page 76: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/76.jpg)
1. Updating
There are three steps involved in the process of updating:
![Page 77: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/77.jpg)
2. Insertion
For an insertion, the new row is initially stored within a special
buffer called the 'insertion row' and there are three steps
involved in the process:
![Page 78: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/78.jpg)
2. Insertion
![Page 79: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/79.jpg)
3. Delete
![Page 80: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/80.jpg)
Example :
![Page 81: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/81.jpg)
![Page 82: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/82.jpg)
![Page 83: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/83.jpg)
![Page 84: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/84.jpg)
![Page 85: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/85.jpg)
![Page 86: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/86.jpg)
![Page 87: Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e355503460f94b24014/html5/thumbnails/87.jpg)
Sample Output