0% found this document useful (0 votes)
6 views1 page

DBMS 7

This document discusses key concepts in database application development, including cursors, embedded SQL, JDBC, SQLJ, and stored procedures. It highlights the differences between JDBC and SQLJ, noting that SQLJ is better for static queries while JDBC is used for dynamic queries. Additionally, it explains how to connect to a data source, manage transactions, and call stored procedures in both JDBC and SQLJ.

Uploaded by

Sourav Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

DBMS 7

This document discusses key concepts in database application development, including cursors, embedded SQL, JDBC, SQLJ, and stored procedures. It highlights the differences between JDBC and SQLJ, noting that SQLJ is better for static queries while JDBC is used for dynamic queries. Additionally, it explains how to connect to a data source, manage transactions, and call stored procedures in both JDBC and SQLJ.

Uploaded by

Sourav Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

6

DATABASE APPLICATION
DEVELOPMENT
Exercise 6.1 Briefly answer the following questions.
1. Explain the following terms: Cursor, Embedded SQL, JDBC, SQLJ, stored pro
cedure.
2. What are the differences between JDBC and SQLJ? Why do they both exist?
3. Explain the term stored procedure, and give examples why stored procedures are
useful.
Answer 6.1 Theanswersaregivenbelow:
1. A cursor enables individual row access of a relation by positioning itself at a
row
and reading its contents. Embedded SQL refers to the usage of SQL commands
within a host program. JDBC stands for Java DataBase Connectivity and is an
interface that allows a Java program to easily connect to any database system.
SQLJ is a tool that allows SQL to be embedded directly into a Java program. A
stored procedure is program that runs on the database server and can be called
with a single SQL statement.
2. SQLJ provides embedded SQL statements. These SQL statements are static in
nature and thus are preprocessed and precompiled. For instance, syntax checking
and schema checking are done at compile time. JDBC allows dynamic queries
that are checked at runtime. SQLJ is easier to use than JDBC and is often a
better option for static queries. For dynamic queries, JDBC must still be used.
3. Stored procedures are programs that run on the database server and can be
called with a single SQL statement. They are useful in situations where the
processing should be done on the server side rather than the client side. Also,
since the procedures are centralized to the server, code writing and maintenance
is simplified, because the client programs do not have to duplicate the
application
logic. Stored procedures can also be used to reduce network communication; the
results of a stored procedure can be analyzed and kept on the database server.
63
64
Chapter 6
Exercise 6.2 Explain how the following steps are performed in JDBC:
1. Connect to a data source.
2. Start, commit, and abort transactions.
3. Call a stored procedure.
How are these steps performed in SQLJ?
Answer 6.2 Theanswersaregivenbelow:
1. Connecting to a data source in JDBC involves the creation of a Connection
object.
Parameters for the connection are specified using a JDBC URL that contains
things like the network address of the database server and the username and
password for connecting.
SQLJ makes calls to the same JDBC drver for connecting to a data source and
usesthesametypeofJDBCURL.
2. Each connection can specify how to handle transactions. If the autocommit flag
is
set, each SQL statement is treated as a separate transaction. If the flag is
turned
off, there is a commit() function call that will actually commit the transaction.
The autocommit flag can also be set in SQLJ. If the flag is not set, transactions
are committed by passing a COMMIT SQL statement to the DBMS.
3. Stored procedures are called from JDBC using the CallableStatement class with
the SQL command {CALL StoredProcedureName}.
SQLJ also uses CALL StoredProcedureName to execute stored prodecures at the
DBMS

You might also like