FreeKB - SQL SELECT in a JSP page in Eclipse
SQL SELECT in a JSP page in Eclipse

Home > Search


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>

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments