Objective: Complete a server-side Java method that retrieves published product data from Oracle AI Database 26ai, and explain how a web application presents the data and image.
House-O-Pets needs a product detail page. A browser calls an HTTPS endpoint such as GET /api/products/1042. A Java application on WebLogic or another suitable server validates the request, retrieves product data using JDBC, and returns a response for the browser to render.
GET /api/products/1042
The image is stored in OCI Object Storage. The database contains a stable media identifier; a separate application media endpoint resolves that identifier to approved content. The browser does not run a Java applet or receive database credentials. This exercise replaces the earlier applet and SQLJ task with a server-side JDBC pattern.
DataSource
PRODUCTS
PRODUCT_ID
NUMBER(18,0)
PRODUCT_NAME
CURRENCY_CODE
PUBLICATION_STATUS
PRICE
NUMBER(12,2)
STOCK_QUANTITY
NUMBER(9,0)
IMAGE_MEDIA_ID
IMAGE_ALT_TEXT
PUBLICATION_STATUS = 'PUBLISHED'
PreparedStatement
Optional.empty()
BigDecimal
Copy this class and replace the TODO method body. No download is required. You do not need to implement a servlet, REST framework, JSON serializer, or image-delivery endpoint.
import java.math.BigDecimal; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Optional; import javax.sql.DataSource; public final class ProductRepository { public record Product(long productId, String name, BigDecimal price, String currencyCode, int stockQuantity, Long imageMediaId, String imageAltText) {} public static Optional<Product> findPublishedProduct( DataSource dataSource, long productId) throws SQLException { // TODO: validate productId, query one published product using a bind, // map its values, handle a nullable image ID, and close resources. throw new UnsupportedOperationException("Complete this method"); } }
This exercise is worth 10 points. After submission, compare your work with the reference solution and rubric. The website displays your response; it does not compile Java, execute SQL, or calculate a score.
Paste the completed class and your answers to questions 2 and 3 below, then select Submit.