SQL COUNT in a JSP page in Eclipse (JSTL)

Home > Search
  by

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 count(id) FROM customers" is stored in a variable named "customersCount".

<sql:query var="customersCount" dataSource="jdbc/mySQL">
    SELECT count(id) FROM customers;
</sql:query>

 

This will print the count.

<c:out value="${customersCount.rowsByIndex[0][0]}" />

 



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 in the box below so that we can be sure you are a human.




Comments