0% found this document useful (0 votes)
11 views

Module 03

Uploaded by

Shreyas B R
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Module 03

Uploaded by

Shreyas B R
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Module-03

1. Explain the concept of views and joins in SQL with an example.


2. Draw and explain 3-tier Architecture and technology relevant to each tier. Mention its
advantages.
The advantages of a 3-tier architecture include:
1. Scalability: It allows for easier scalability as each tier can be scaled independently, enabling
better resource allocation and management.
2. Modularity: The architecture promotes modularity by separating concerns into presentation,
application logic, and data management tiers, making the system more maintainable and easier to
update.
3. Flexibility: Developers can use different technologies for each tier, providing flexibility in design
and implementation choices.

3. What is SQLJ? How it is different from JDBC. Write a short note on Drivers in JDBC (8+4)
Answer:- SQLJ is a technology that embeds SQL queries in Java programs. It allows developers to
write SQL queries directly in Java code using special SQLJ syntax, which is then preprocessed by a
SQLJ translator to generate standard Java code that interacts with the database using JDBC.
The main difference between SQLJ and JDBC is in how SQL queries are handled. With JDBC, SQL
queries are typically written as strings within Java code, which can lead to potential syntax errors
and lack of type safety. In contrast, SQLJ provides a more integrated approach, allowing developers
to write SQL queries directly in Java code, making the code more readable, maintainable, and less
error-prone.
comparison of SQLJ and JDBC in tabular form:

Feature SQLJ JDBC

Embeds SQL queries in Java code using SQL queries are written as strings within
Syntax
SQLJ syntax Java code

Provides better type safety as queries are Less type safety as queries are
Type Safety
checked at compile-time represented as strings

Offers seamless integration of SQL Provides a lower-level API for database


Integration
queries with Java code interactions

May offer better performance due to Performance can vary depending on query
Performance
precompiled and optimized queries implementation

Can reduce development time by


May require more code and effort for
Development Time providing a more concise way to write
query writing and maintenance
queries
Drivers in JDBC are software components that enable Java applications to interact with different
types of databases using the JDBC API.
There are four types of JDBC drivers:
1. Type 1 (JDBC-ODBC bridge driver): This driver translates JDBC calls into ODBC calls, allowing
Java applications to interact with ODBC-compliant databases. However, this driver is platform-
dependent and has performance issues.
2. Type 2 (Native-API driver): This driver uses a database-specific native API to interact with the
database. It provides better performance than the Type 1 driver but is still platform-dependent.
3. Type 3 (Network protocol driver): This driver uses a middleware component to translate
JDBC calls into a database-independent protocol, which is then converted into a database-specific
protocol by a server-side component. This driver is platform-independent but may have
performance overhead due to the middleware layer.
4. Type 4 (Thin driver): Also known as the “Direct to Database Pure Java Driver,” this driver
communicates directly with the database using a vendor-specific protocol. It is platform-
independent and provides the best performance among the JDBC driver types.
Each type of driver has its advantages and disadvantages, and the choice of driver depends on
factors such as database vendor, deployment environment, and performance requirements.
5. Differentiate between Dynamic and Embedded SQL
6. Explain Cursors in Embedded SQL
Cursors in embedded SQL are programming constructs used to handle result sets returned by SQL
queries within a procedural programming language, such as C, C++, COBOL, or PL/SQL. They allow
developers to iterate through the rows of a result set one by one, enabling them to perform
operations on each row individually.

Here's how cursors typically work in embedded SQL:

1. Declaration: Cursors are first declared within the embedded SQL code block. This declaration
specifies the SQL query that will be associated with the cursor.
For example: EXEC SQL DECLARE cursor_name CURSOR FOR SELECT column1, column2 FROM
table_name WHERE condition;
2. Opening: Once declared, the cursor needs to be opened before fetching any rows from the
result set. This step establishes the connection between the cursor and the result set produced
by the SQL query.
For example: EXEC SQL OPEN cursor_name;
3. Fetching: After opening the cursor, rows from the result set can be fetched one at a time. The
fetched rows are typically stored in variables or data structures within the procedural
programming language for further processing.
For example: EXEC SQL FETCH NEXT FROM cursor_name INTO :variable1, :variable2;
This statement fetches the next row from the result set associated with cursor_name and stores
the values of column1 and column2 into variable1 and variable2, respectively.

4. Processing: Once a row is fetched, the procedural code can perform operations on the data
stored in the variables. This might involve computations, comparisons, or any other relevant
actions.

5. Looping: Steps 3 and 4 are typically performed in a loop until all rows have been fetched. This
loop continues until there are no more rows to fetch from the result set.

6. Closing: After all rows have been processed, the cursor should be closed to release associated
resources.
For example: EXEC SQL CLOSE cursor_name;
Using cursors in embedded SQL allows developers to manipulate result sets row by row, which can
be useful for tasks such as data processing, reporting, or batch operations. However, it's important
to use cursors judiciously, as they can sometimes lead to performance issues, especially when
dealing with large result sets.
7. Write a note on Specifying Constraints as Assertions in SQL. Also explain how assertions and
triggers are defined with an example.
8. What are stored procedures in SQL? Elaborate.

33

Explain the following:


Nested Queries:

Co related nested queries


9. Aggregate Functions in Sql:

Grouping: The Group by and having Clauses


10. Explain the commands in Sql
Discuss all form of Alter command

You might also like