Java - SQL select

by
Jeremy Canfield |
Updated: March 23 2022
| Java articles
This assumes you have created your first dynamic web project in Eclipse and you can can connect to a SQL database in Java using Eclipse via DataSource or connect to a SQL database in Java using Eclipse via DriverManager.
FIrst you will import SQL and C in your JSP page.
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
In this example, the results of "SELECT * FROM customers" is stored in a variable named "customers".
<sql:query var="customers" dataSource="jdbc/mySQL">
SELECT * FROM customers;
</sql:query>
You can then loop through each result and print the customer name.
<c:forEach var="customer" items="${customers.rows}">
<c:out value="${customer.name}" />
</c:forEach>
Did you find this article helpful?
If so, consider buying me a coffee over at