PowerPoint Presentation04e-BM/NS/HDCV/FSOFT v2/3
Lesson 6:
Database Programming
with Java
04e-BM/NS/HDCV/FSOFT v2/3
Course Objective
JDBC Basics
Statement
ResultSet
PreparedStatement
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Learning Approach
The following are strongly suggested for a better learning and
understanding of this course:
Noting down the key concepts in the class
Analyze all the examples / code snippets provided
Study and understand the self study topics
Completion and submission of all the assignments, on time
Completion of the self review questions in the lab guide
Study and understand all the artifacts including the reference
materials / e-learning / supplementary materials specified
Completion of the project (if application for this course) on time
inclusive of individual and group activities
Taking part in the self assessment activities
Participation in the doubt clearing sessions
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
JDBC BASICS
Session 1
04e-BM/NS/HDCV/FSOFT v2/3
JDBC (Java DataBase Connectivity) provides a standard library for
accessing relational databases
JDBC consists of two parts:
JDBC API, a purely Java-based API
JDBC Driver Manager,which communicates with vendor-specific drivers
that perform the real communication with the database.
JDBC classes are in the java.sql package
Current JDBC version: 3.0
04e-BM/NS/HDCV/FSOFT v2/3
Vendor independent
Platform independent
04e-BM/NS/HDCV/FSOFT v2/3
Left side, Type 1: JDBC-ODBC Bridge plus ODBC Driver
This combination provides JDBC access via ODBC drivers. ODBC binary
code -- and in many cases, database client code -- must be loaded
on each client machine that uses a JDBC-ODBC Bridge. Sun provides a
JDBC-ODBC Bridge driver, which is appropriate for experimental use
and for situations in which no other driver is available.
Right side, Type 2: A native API partly Java technology-enabled
driver
This type of driver converts JDBC calls into calls on the client
API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that,
like the bridge driver, this style of driver requires that some
binary code be loaded on each client machine.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Right side, Type 3: Pure Java Driver for Database Middleware
This style of driver translates JDBC calls into the middleware
vendor's protocol, which is then translated to a DBMS protocol by a
middleware server. The middleware provides connectivity to many
different databases.
Left side, Type 4: Direct-to-Database Pure Java Driver
This style of driver converts JDBC calls into the network protocol
used directly by DBMSs, allowing a direct call from the client
machine to the DBMS server and providing a practical solution for
intranet access.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
04e-BM/NS/HDCV/FSOFT v2/3
1. Load the driver
3. Create a Statement object
4. Executing the Statement
6. Process the results.
7. Close the connection
04e-BM/NS/HDCV/FSOFT v2/3
Register with DriverManager
No need to register with DriverManager.
How to specify the Driver class.
Refer to the driver documentation.
Some examples.
04e-BM/NS/HDCV/FSOFT v2/3
Need username, password
Examples:
jdbc:oracle:thin:@localhost:1521:orcl
jdbc:mysql://127.0.0.1:3306/books
04e-BM/NS/HDCV/FSOFT v2/3
JDBC Statement Object
A Statement object is what sends your SQL statement to the
DBMS
Create a Statement object and then execute it, supplying
appropriate method with the SQL statement you want to send.
Statement stmt = con.createStatement();
For a SELECT statement, the method to use is executeQuery.
stmt.executeQuery( “SELECT * FROM XXX");
For statements that create or modify tables, the method to use is
executeUpdate.
stmt.executeUpdate( "INSERT INTO XXX… “);
04e-BM/NS/HDCV/FSOFT v2/3
ResultSet object
A ResultSet object is a table of data representing a database
result set, which is usually generated by executing a statement
that queries the database.
You access the data in a ResultSet object through a cursor. This
cursor is a pointer that points to one row of data in the
ResultSet. Initially, the cursor is positioned before the first
row.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
ResultSet type
TYPE_FORWARD_ONLY: The result set cannot be scrolled; its cursor
moves forward only, from before the first row to after the last
row. The rows contained in the result set depend on how the
underlying database generates the results. That is, it contains the
rows that satisfy the query at either the time the query is
executed or as the rows are retrieved.
TYPE_SCROLL_INSENSITIVE: The result can be scrolled; its cursor can
move both forward and backward relative to the current position,
and it can move to an absolute position. The result set is
insensitive to changes made to the underlying data source while it
is open. It contains the rows that satisfy the query at either the
time the query is executed or as the rows are retrieved.
TYPE_SCROLL_SENSITIVE: The result can be scrolled; its cursor can
move both forward and backward relative to the current position,
and it can move to an absolute position. The result set reflects
changes made to the underlying data source while the result set
remains open.
The default ResultSet type is TYPE_FORWARD_ONLY.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
ResultSet Concurrency
The concurrency of a ResultSet object determines what level of
update functionality is supported.
There are two concurrency levels:
CONCUR_READ_ONLY: The ResultSet object cannot be updated using the
ResultSet interface.
CONCUR_UPDATABLE: The ResultSet object can be updated using the
ResultSet interface.
The default ResultSet concurrency is CONCUR_READ_ONLY.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Cursor Holdability
Calling the method Connection.commit can close the ResultSet
objects that have been created during the current transaction. In
some cases, however, this may not be the desired behavior. The
ResultSet property holdability gives the application control over
whether ResultSet objects (cursors) are closed when commit is
called.
HOLD_CURSORS_OVER_COMMIT: ResultSet cursors are not closed; they
are holdable: they are held open when the method commit is called.
Holdable cursors might be ideal if your application uses mostly
read-only ResultSet objects.
CLOSE_CURSORS_AT_COMMIT: ResultSet objects (cursors) are closed
when the commit method is called. Closing cursors when this method
is called can result in better performance for some
applications.
The default cursor holdability varies depending on your DBMS.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
ResultSet navigation
Moves the cursor froward one row from its current position.
previous()
Moves the cursor to the previous row in this ResultSet
object.
first()
Moves the cursor to the first row in this ResultSet object.
last()
Moves the cursor to the last row in this ResultSet object.
beforeFirst()
Moves the cursor to the front of this ResultSet object, just before
the first row. This method has no effect if the result set contains
no rows.
afterLast()
Moves the cursor to the end of this ResultSet object, just after
the last row. This method has no effect if the result set contains
no rows.
getRow()
*
Note that the default sensitivity of a ResultSet is
TYPE_FORWARD_ONLY, which means that it cannot be scrolled; you
cannot call any of these methods that move the cursor, except next,
if your ResultSet cannot be scrolled.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
absolute(int row)
Moves the cursor to the given row number in this ResultSet object.
If the row number is positive, the cursor moves to the given row
number with respect to the beginning of the result set. The first
row is row 1, the second is row 2, and so on. If the given row
number is negative, the cursor moves to an absolute row position
with respect to the end of the result set. For example, calling the
method absolute(-1) positions the cursor on the last row; calling
the method absolute(-2) moves the cursor to the next-to-last row,
and so on.
relative(int rows)
*
Note that the default sensitivity of a ResultSet is
TYPE_FORWARD_ONLY, which means that it cannot be scrolled; you
cannot call any of these methods that move the cursor, except next,
if your ResultSet cannot be scrolled.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
The ResultSet interface declares getter methods (example:
getBoolean, getLong, …) for retrieving column values from the
current row.
You can retrieve values using either the index number of the column
or the alias or name of the column.
The column index is usually more efficient. Columns are numbered
from 1.
For maximum portability, result set columns within each row should
be read in left-to-right order, and each column should be read only
once.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
With CONCUR_UPDATABLE ResultSet, you can update values using
updateXXX() method.
You can update values using either the index number of the column
or the name of the column.
However, none of these updater methods modifies the database; you
must call the method ResultSet.updateRow to update the
database.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Updating a row
Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE)
rs.first();
rs.updateInt(2,2345); //rs.update<Type>
rs.updateRow();
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Statement st = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE)
rs.first();
rs.update<Type>
rs.insertRow();
04e-BM/NS/HDCV/FSOFT v2/3
Step 1: Positioning the cursor
// Move the cursor to the last row of the result set
rs.last();
// Deleting the row from the result set
rs.deleteRow();
04e-BM/NS/HDCV/FSOFT v2/3
*
Note: Not all JDBD drivers support inserting new rows with the
ResultSet interface. If you attempt to insert a new row and your
JDBC driver database does not support this feature, a
SQLFeatureNotSupportedException exception is thrown.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
DisplayAuthors
Displays the data in a JTextArea
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
3
10
12 static String JDBC_DRIVER =
"oracle.jdbc.driver.OracleDriver";
13 String DATABASE_URL =
"jdbc:oracle:thin:@localhost:1521:orcl";
16 // and querying database
17 private Connection connection;
18 private Statement statement;
21 // results and displays results in window
22 public DisplayAuthors()
25
*
Line 5: Imports package java.sql, which contains classes and
interfaces for the JDBC API.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
27 try {
33 Class.forName( JDBC_DRIVER );
36 connection = DriverManager.getConnection( DATABASE_URL );
39 statement = connection.createStatement();
44
47 ResultSetMetaData metaData = resultSet.getMetaData();
48 int numberOfColumns = metaData.getColumnCount();
Line 33: Loads the class definition for the database driver.
Lines 36: Declare and initialize a Connection reference called
connection.
Line 39: Invokes Connection method createStatement to obtain an
object that implements interface Statement.
Line 43: Use the Statement object’s executeQuery method to execute
a query that selects all the author information from table
authors.
Line 47: Obtains the metadata for the ResultSet.
Line 48: Uses ResultSetMetaData method getColumnCount to retrieve
the number of columns in the ResultSet.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
51 results.append( metaData.getColumnName( i ) + "\t" );
52
58 results.append( resultSet.getObject( i ) + "\t" );
59
64 JTextArea textArea = new JTextArea( results.toString() );
65 Container container = getContentPane();
68
70 setVisible( true ); // display window
71
Line 51:Append the column names to the StringBuffer results.
Line 58:Append the data in each ResultSet row to the StringBuffer
results.
Lines 64-70: Create the GUI that displays the StringBuffer results,
set the size of the application window and show the application
window.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
75 catch ( SQLException sqlException ) {
76 JOptionPane.showMessageDialog( null,
sqlException.getMessage(),
77 "Database Error", JOptionPane.ERROR_MESSAGE );
83 catch ( ClassNotFoundException classNotFound ) {
84 JOptionPane.showMessageDialog( null,
classNotFound.getMessage(),
86
91 finally {
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
99 catch ( SQLException sqlException ) {
112 {
114 window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
04e-BM/NS/HDCV/FSOFT v2/3
PreparedStatement Object
An object that represents a precompiled SQL statement.
PreparedStatement object is given an SQL statement when it is
created. This SQL statement is sent to the DBMS right away, where
it will be compiled.
When the PreparedStatement is executed, the DBMS can just run the
PreparedStatement 's SQL statement without having to compile it
first.
PreparedStatement objects are used more for SQL statements that
take parameters. The advantage of using SQL statements that take
parameters is that you can use the same statement and supply it
with different values each time you execute it.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
PreparedStatement Example
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
JDBC ADVANCED
Session 2
04e-BM/NS/HDCV/FSOFT v2/3
Handling SQLExceptions
When JDBC encounters an error during an interaction with a data
source, it throws an instance of SQLException as opposed to
Exception. The SQLException instance contains the following
information:
A description of the error.
Retrieve the String object that contains this description by
calling the method SQLException.getMessage.
A SQLState code.
These codes and their respective meanings have been standardized by
ISO/ANSI and Open Group (X/Open), although some codes have been
reserved for database vendors to define for themselves. This String
object consists of five alphanumeric characters. Retrieve this code
by calling the method SQLException.getSQLState.
An error code.
This is an integer value identifying the error that caused the
SQLException instance to be thrown. Its value and meaning are
implementation-specific and might be the actual error code returned
by the underlying data source. Retrieve the error by calling the
method SQLException.getErrorCode.
A cause.
A SQLException instance might have a causal relationship, which
consists of one or more Throwable objects that caused the
SQLException instance to be thrown. To navigate this chain of
causes, recursively call the method SQLException.getCause until a
null value is returned.
A reference to any chained exceptions.
If more than one error occurs, the exceptions are referenced
through this chain. Retrieve these exceptions by calling the method
SQLException.getNextException on the exception that was
thrown.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Retrieving Exceptions
public static void printSQLException(SQLException ex) {
for (Throwable e : ex) {
if (e instanceof SQLException) {
04e-BM/NS/HDCV/FSOFT v2/3
Retrieving Exceptions
For example, if you execute a SQL statement but the table does not
exist, the output will be similar to the following:
SQLState: 42Y55
Message: 'DROP TABLE' cannot be performed on ‘BOOKS.SAMPLEAUTHORS'
because it does not exist.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Batch updates
A set of multiple update statements that is submitted to the
database for processing as a batch
Statement, PreparedStatement and CallableStatement can be used to
submit batch updates
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
04e-BM/NS/HDCV/FSOFT v2/3
Indivisible unit of work
04e-BM/NS/HDCV/FSOFT v2/3
Transaction
A transaction is a set of one or more statements that is executed
as a unit, so either all of the statements are executed, or none of
the statements is executed.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Transaction Processing
Start transaction
Disable auto-commit mode
The way to allow two or more statements to be grouped into a
transaction is to disable the auto-commit mode.
con.setAutoCommit(false);
Commit
After the auto-commit mode is disabled, no SQL statements are
committed until you call the method commit() explicitly. All
statements executed after the previous call to the method commit()
are included in the current transaction and committed together as a
unit.
Enable auto-commit mode
Rollback transaction
If any error of abnormal case happened, you may want to aborts this
transaction and restores values to what they were before the
attempted update:
con.rollback()
04e-BM/NS/HDCV/FSOFT v2/3
Setting and Rolling Back to Savepoints
An SQL savepoint represents the state of data and schemas at a
particular point in time within a unit of work.
To create a savepoint:
rollback(Savepoint savepoint)
04e-BM/NS/HDCV/FSOFT v2/3
RowSet
A JDBC RowSet object holds tabular data in a way that makes it more
flexible and easier to use than a result set.
All RowSet objects are derived from the ResultSet interface and
therefore share its capabilities. What makes JDBC RowSet objects
special is that they add these new capabilities:
Function as JavaBeans Component
Add Scrollability or Updatability
Oracle has defined five RowSet interfaces for some of the more
popular uses of a RowSet, and standard reference are available for
these RowSet interfaces:
JdbcRowSet
CachedRowSet
WebRowSet
JoinRowSet
FilteredRowSet
04e-BM/NS/HDCV/FSOFT v2/3
Function as JavaBeans Component
All RowSet objects are JavaBeans components. This means that they
have the following:
Properties
All RowSet objects have properties. A property is a field that has
corresponding getter and setter methods.
JavaBeans Notification Mechanism
RowSet objects use the JavaBeans event model, in which registered
components are notified when certain events occur. For all RowSet
objects, three events trigger notifications:
A cursor movement
A change to the entire RowSet contents
The notification of an event goes to all listeners, components that
have implemented the RowSetListener interface and have had
themselves added to the RowSet object's list of components to be
notified when any of the three events occurs.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Setting Up Listeners
A listener for a RowSet object is a component that implements the
following methods from the RowSetListener interface:
cursorMoved: Defines what the listener will do, if anything, when
the cursor in the RowSet object moves.
rowChanged: Defines what the listener will do, if anything, when
one or more column values in a row have changed, a row has been
inserted, or a row has been deleted.
rowSetChanged: Defines what the listener will do, if anything, when
the RowSet object has been populated with new data.
An example of a component that might want to be a listener is a
BarGraph object that graphs the data in a RowSet object. As the
data changes, the BarGraph object can update itself to reflect the
new data.
The following line of code means that every time the cursor for the
crs objects moves, values in crs are changed, or crs as a whole
gets new data, the BarGraph object bar will be notified:
crs.addRowSetListener(bar);
crs.removeRowSetListener(bar);
04e-BM/NS/HDCV/FSOFT v2/3
Add Scrollability or Updatability
Some DBMSs do not support result sets that can be scrolled
(scrollable), and some do not support result sets that can be
updated (updatable). If a driver for that DBMS does not add the
ability to scroll or update result sets, you can use a RowSet
object to do it.
A RowSet object is scrollable and updatable by default, so by
populating a RowSet object with the contents of a result set, you
can effectively make the result set scrollable and updatable.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
04e-BM/NS/HDCV/FSOFT v2/3
A RowSet object is considered either connected or
disconnected.
A connected RowSet object uses a JDBC driver to make a connection
to a relational database and maintains that connection throughout
its life span.
JdbcRowSet
A disconnected RowSet object makes a connection to a data source
only to read in data from a ResultSet object or to write data back
to the data source. After reading data from or writing data to its
data source, the RowSet object disconnects from it, thus becoming
"disconnected." During much of its life span, a disconnected RowSet
object has no connection to its data source and operates
independently.
CachedRowSet
WebRowSet
JoinRowSet
FilteredRowSet
04e-BM/NS/HDCV/FSOFT v2/3
Stored Procedures
A stored procedure is a group of SQL statements that form a logical
unit and perform a particular task, and they are used to
encapsulate a set of operations or queries to execute on a database
server.
Stored procedures can be compiled and executed with different
parameters and results, and they can have any combination of input,
output, and input/output parameters.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
String queryDrop = "DROP PROCEDURE IF EXISTS SHOW_AUTHORS";
String createProcedure =
04e-BM/NS/HDCV/FSOFT v2/3
04e-BM/NS/HDCV/FSOFT v2/3
Connection pool
*
04e-BM/NS/HDCV/FSOFT v2/3
Connection pool
Opening and maintaining a database connection for each user, is
costly and wastes resources.
In connection pooling, after a connection is created, it is placed
in the pool and it is used over again so that a new connection does
not have to be established.
*
04e-BM/NS/HDCV/FSOFT v2/3
Connection pool
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Connection pool
A new client #2 is assigned to a free connection
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Connection pool
Client #1 is disconnected, and free a connection for use
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Connection pool
A new client #3 is assigned to the free connection
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
You may write your own code
You may using Application server which supported connection pool
(for ex: Tomcat, Jboss, Jetty, …)
You may using other libraries
*
04e-BM/NS/HDCV/FSOFT v2/3
Application server
04e-BM/NS/HDCV/FSOFT v2/3
</description>
<res-ref-name>
jdbc/EmployeeDB
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
04e-BM/NS/HDCV/FSOFT v2/3
Tomcat configuration
The configuration properties for Tomcat's standard data source
resource factory are as follows:
driverClassName - Fully qualified Java class name of the JDBC
driver to be used.
username - Database username to be passed to our JDBC driver.
password - Database password to be passed to our JDBC driver.
url - Connection URL to be passed to our JDBC driver.
initialSize - The initial number of connections that will be
created in the pool during pool initialization. Default: 0
maxActive - The maximum number of connections that can be allocated
from this pool at the same time. Default: 8
minIdle - The minimum number of connections that will sit idle in
this pool at the same time. Default: 0
maxIdle - The maximum number of connections that can sit idle in
this pool at the same time. Default: 8
*
04e-BM/NS/HDCV/FSOFT v2/3
04e-BM/NS/HDCV/FSOFT v2/3
conn.close();
04e-BM/NS/HDCV/FSOFT v2/3
HSQL in-memory
SampleHSQL.jar
SampleHSQL.zip
MySQL
*
Guide to the student to using HSQL in-memory and MySQL at very
basics. These files are in \Guide folder.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Summary
JDBC is an API specification developed by Sun Microsystems that
defines a uniform interface for accessing different relational
databases. The primary function of the JDBC API is to allow the
developer to issue SQL statements and process the results in a
consistent, database-independent manner.
A JDBC driver translates standard JDBC calls into a network
protocol or client API call that facilitates communication with the
database. This transla-tion provides JDBC applications with
database independence.
The basic process of connecting to a database via JDBC goes like
this: regis-ter the JDBC driver, establish a database connection,
execute an SQL state-ment, process the results, close the database
connection.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Summary(cont)
A prepared statement is an SQL statement that is precompiled by the
data-base. Through precompilation, prepared statements improve the
performance of SQL commands that are executed multiple times (given
that the database supports prepared statements).
A transaction is a set of SQL statements that are grouped such that
all state-ments are guaranteed to be executed or the entire
operation will fail. If all statements execute successfully, the
results are committed to the database; otherwise, all changes are
rolled back.
A stored procedure is an SQL operation that is stored on the
database server. Stored procedures are usually written in an SQL
dialect that has been expanded to include conditional statements,
looping constructs, and other procedural programming
features.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Q&A