Ciao a tutti,
Utilizzo Netbeans 7.4, ho problemi con l'utilizzo di un database.
nell'appartato "Services" è presente e attiva la connessione, database connection:
jdbc:derby://localhost:1527/sample [app on APP]
se io clicco su + appare un db dal nome 'APP'
se io clicco ancora su + appare 'Tables'
se clicco ancora su + mi visualizza la tabella 'CUSTOMER'
se clicco su 'CUSTOMER' con il bottone destro del mouse 'view data', mi visualizza tutti i dati della tabella.
Genero un nuovo progetto 'JAVA web ' e scelgo 'web application'.
Creo un nuovo deployment descriptor web.xml
codice:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<resource-ref>
<res-ref-name>jdbc/APP</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
Ok, il <res-ref-name> è il nome di riferimento usato nell'albero JNDI .
Come faccio a sapere il nome esatto da utilizzare?
Perchè utilizzando una pagina JSP mi riporta un exception nel navigatore, come se la tabella non esistesse, vi riporto il codice:
codice:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%--
Document : index
Created on : Jan 20, 2014, 6:10:53 PM
Author : X
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<sql:query var="allRows" dataSource="jdbc/APP">
SELECT * FROM customer
</sql:query>
<table border="1">
<!-- column headers -->
<tr>
<c:forEach var="columnName" items="${allRows.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
</tr>
<!-- column data -->
<c:forEach var="row" items="${allRows.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
</body>
</html>
e l'exception visualizzata nel navigatore è la seguente, dove sbaglio?
HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException:
SELECT * FROM customer
: Table/View 'CUSTOMER' does not exist.
root cause
java.sql.SQLSyntaxErrorException: Table/View 'CUSTOMER' does not exist.
root cause
org.apache.derby.client.am.SqlException: Table/View 'CUSTOMER' does not exist.
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs.
Grazie,
Roberto