Programming Assignment Unit 7
Programming Assignment Unit 7
In developing an online marketplace platform that manages product listings, user accounts,
transactions, and feedback, ensuring robust and reliable database operations is essential. At the
core of this reliability are transactions, SQL execution methods, and database connectivity
interfaces such as JDBC and ODBC.
Transactions play a critical role in maintaining data consistency and integrity in a multi-user
environment like an online marketplace. For example, when a user places an order, several
operations happen: the product quantity is updated, the order is logged, the payment is processed,
and a confirmation is generated. These operations must all succeed together or fail as a unit—this
is where transactions become vital.
To implement this, SQL transaction commands like BEGIN TRANSACTION, COMMIT, and
ROLLBACK would be used in the application code. In pseudocode:
BEGIN TRANSACTION;
UPDATE products SET stock = stock - 1 WHERE product_id = 101;
INSERT INTO orders (...) VALUES (...);
-- If any error occurs, roll back
ROLLBACK;
-- Else
COMMIT;
This ensures that all database changes related to the order are processed reliably and revert in
case of failure.
SQL can be executed in three main ways: static, dynamic, and embedded, each serving
different use cases.
Static SQL involves pre-defined, fixed SQL queries compiled into the application. These are
used where the structure of queries does not change. For example, fetching user login
credentials:
● Since these queries are precompiled, they offer better performance and are less error-
prone.
● Dynamic SQL is used when queries need to be built at runtime. This is useful in flexible
search filters where users can select multiple categories, brands, and price ranges.
Dynamic SQL can adapt to various combinations without needing hardcoded queries.
Embedded SQL refers to writing SQL statements directly inside a host language like Java or C.
It integrates database logic into the application seamlessly. An example would be:
EXEC SQL SELECT product_name INTO :productName FROM products WHERE product_id
= :productId;
● This tight integration allows efficient data access and better code readability in
transactional systems.
Together, these methods allow the online marketplace to handle both fixed operations (like
logging in) and dynamic features (like advanced product search) efficiently.
To support a scalable and flexible marketplace, choosing the right database connectivity
interface is important.
conn = pyodbc.connect('DSN=MarketplaceDB')
cursor = conn.cursor()
cursor.execute("SELECT * FROM users")
JDBC is preferred for Java environments due to tighter integration, while ODBC is suitable for
heterogeneous platforms. Both provide secure, reliable access to database resources essential for
real-time operations in the marketplace.
References:
1. Vidhya, V., Jeyaram, G., & Ishwarya, K. (2016). Database Management Systems. Alpha
Science International.
2. Radakovic, M. (2017, January 13). Understanding SQL Server database static data.
SQLShack. https://www.sqlshack.com/understanding-sql-server-database-static-data-fits-
database-lifecycle-management/
3. Baeldung. (n.d.). A guide to JDBC. Baeldung. https://www.baeldung.com/java-jdbc
4. Insightsoftware. (2023, June 10). What is ODBC – Open database connectivity.
Insightsoftware. https://insightsoftware.com/blog/what-is-odbc/
5. Zanini, A. (2023, February 14). Database transactions 101: The essential guide.
DbVisualizer. https://www.dbvis.com/thetable/database-transactions-101-the-essential-
guide/