Select data from Firebird by means of JSTL in Netbeans 8

In last post I describe how create website in JSTL. In this post we select data from database and display them into table.

Open in Netbeans our NewJSTL project. Right click the Libraries node and choose Add JAR/Folder.

c30Choose from opened window jdbc driver for your database. On the list of libraries you see this jar file.

c40Open your index.jsp file and paste into it this code:


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSTL</title>
    </head>
    <body>
        <h1>JSTL page selected data from database</h1>
        <sql:setDataSource  driver="org.firebirdsql.jdbc.FBDriver"
     url="jdbc:firebirdsql://localhost:3050/D:/bazy_danych/test.fdb"
     user="SYSDBA"  password="masterkey"/> 
<sql:query var="result">SELECT * from testdb;</sql:query> 
<table border="1" width="100%">
<tr><th>ID</th><th>Name</th></tr>
<c:forEach var="row" items="${result.rows}">
<tr>
   <td><c:out value="${row.id}"/></td>
   <td><c:out value="${row.name}"/></td>  
</tr>
</c:forEach>
</table></body></html>

c42

Change values connected to database , name of table and column for yours.

Check if you have connected to the database in Services window.

z15Run your application.

c43