Bootstrap FreeKB - Java - SQL select
Java - SQL select

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 103d28 in the box below so that we can be sure you are a human.