Ich habe die Datei Application.jspx:
und die Datei ApplicationManagedBean:
Beides lässt sich einwandfrei compilieren. Der Server bringt keine Fehlermeldung. Die Seite erscheint mit dem Label "ID", jedoch ohne Inhalt der Datenbank (obwohl Daten in der Spalte "ID_APPLICATION" vorhanden wären). Die Datenbankanbindung funktioniert einwandfrei, hab mir die Daten vorher mal per "static void main" über die Konsole ausgeben lassen.
"Return"-Statement falsch?? Kann man sowas eleganter lösen?
Code:
<?xml version="1.0" encoding="UTF-8"?> <!-- Document : Application Created on : 20.03.2008, 15:00:18 Author : bergmann --> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/> <!-- any content can be specified here, e.g.: --> <jsp:element name="text"> <jsp:attribute name="lang">EN</jsp:attribute> <jsp:body> <f:view> <h:dataTable value="#{ApplicationManagedBean.Table}" var="dbRow"> <h:column> <f:facet name="header"> <f:verbatim>ID</f:verbatim> </f:facet> <h:outputText value="#{dbRow.ID_APPLICATION}"/> </h:column> </h:dataTable> </f:view> </jsp:body> </jsp:element> </jsp:root>
Code:
package dataController; import java.sql.*; import javax.sql.*; import javax.naming.*; import javax.servlet.jsp.jstl.sql.*; public class ApplicationManagedBean { /** Creates a new instance of ApplicationManagedBean */ public ApplicationManagedBean() { } private String Table = new String(); public void setTable(String table) { this.Table = table; } public String getTable() { try { // Parameter für Verbindungsaufbau definieren String driver = "..."; String url = "..."; String user = "..."; String password = "..."; // JDBC-Treiber laden Class.forName(driver); // Verbindung aufbauen Connection con; con = DriverManager.getConnection(url, user, password); // SQL-Anweisungen ausführen PreparedStatement stmt = con.prepareStatement("SELECT * FROM APPLICATION"); ResultSet rs = stmt.executeQuery(); // Ergebnis abfragen return getTable(); } catch(Exception ex) {return (null); } } }
"Return"-Statement falsch?? Kann man sowas eleganter lösen?