Silvestrini
Silvestrini

Reputation: 445

Getting row data from Database to JSP

Im trying to display the data from a Databse using joins. I manage to display the first table but I get a null exception error when trying to display the other data. Im doing this via the Java Class.

Here is the function...

public List<administration> fullList() throws Exception{

    List<administration> result = new ArrayList<administration>();

    try{
        Class.forName("com.mysql.jdbc.Driver");
        connectMe = DriverManager.getConnection(url+dbName, userNameDB, passwordDB);

        String query = "SELECT  \n" + 
                " ControlAccess.UserName, \n" +
                " ControlAccess.Pass, \n" +
                " Users.First_Name,\n" +
                " Users.Last_Name, \n" +
                " UserInfo.Age, \n" +
                " UserInfo.Country,\n" +
                " UserInfo.Address,\n" +
                " UserInfo.ZipCode,\n" +
                " Sessions.Matrix1,\n" +
                " Sessions.Matrix2,\n" +
                " Sessions.Result,\n" +
                " FilePath.LocationFiles\n" +
                " FROM MatrixUsers.UserInfo \n" +
                " INNER JOIN MatrixUsers.Users\n" +
                " ON UserInfo.idUserInfo = Users.idUsers\n" +
                " INNER JOIN MatrixUsers.ControlAccess \n" +
                " ON ControlAccess.idControlAccess = UserInfo.idUserInfo\n" +
                " INNER JOIN MatrixUsers.Sessions \n" +
                " ON Sessions.idSessions = ControlAccess.idControlAccess\n" +
                " INNER JOIN MatrixUsers.FilePath \n" +
                " ON FilePath.idFilePath = Sessions.idSessions";

        selectUsers = connectMe.prepareStatement(query);
        results = selectUsers.executeQuery();

        while(results.next()) {

            administration admin = new administration();

            admin.setUserName(results.getString("UserName"));
            admin.setPassword(results.getString("Pass"));
            admin.setFirstname(results.getString("First_Name"));
            admin.setLastname(results.getString("Last_Name"));
            admin.setAge(results.getInt("Age"));
            admin.setCountry(results.getString("Country"));
            admin.setAddress(results.getString("Address"));
            admin.setZipcode(results.getInt("ZipCode"));
            admin.setMatrix1(results.getString("Matrix1"));
            admin.setMatrix2(results.getString("Matrix2"));
            admin.setResult(results.getString("Result"));
            admin.setLocation(results.getString("LocationFiles"));
            result.add(admin);

        }

       results.close();
       connectMe.close();

    }catch(Exception e) {
        e.printStackTrace();
    }

    return result;
}

Here is the sets and gets:

 public String getUsername() {
    return username;    
}

public String getPassword() {
    return password;
}

public String getFirstname() {
    return firstName;
}

public String getLastname() {
    return lastName;
}

public int getAge() {
    return age;
}

public String getCountry() {
    return country;
}

public String getAddress() {
    return address;
}

public int getZipcode() {
    return zipcode;
}

public String getMatrix1() {
    return Matrix1;
}

public String getMatrix2() {
    return Matrix2;
}

public String getResult() {
    return Result;
}

public String getLocation() {
    return location;
}

public int getID() {
    return id;
}

public void setUserName(String aUser) {
    username = aUser;
}

public void setPassword(String aPass) {
    password = aPass;
}

public void setFirstname(String aFirstname) {
    firstName = aFirstname;
}

public void setLastname(String aLastname) {
    lastName = aLastname;
}

public void setAge(int anAge) {
    age = anAge;
}

public void setCountry(String aCountry) {
    country = aCountry;
}

public void setAddress(String anAddress) {
    address = anAddress; 
}

public void setZipcode(int aZipcode) {
    zipcode = aZipcode;
}

public void setMatrix1(String aMatrix) {
    Matrix1 = aMatrix;
}

public void setMatrix2(String aMatrix) {
    Matrix2 = aMatrix;
}

public void setResult(String aResult) {
    Result = aResult;
}

public void setLocation(String aLocation) {
    location = aLocation;
}

I display using iteration in the JSP. Any extra info you need just ask! I'll be looking to see if I can find the error myself. Also I apologize for the huge query statement, its part of a assignment and its requisite.

JSP code:

<table>
        <c:forEach var="admin" items="${result}">
            <tr>

                <td><c:out value = "${admin.username}" /> </td>
                <td>${admin.password} </td>
                <td>${admin.firstName} </td>
                <td>${admin.lastName} </td>
                <td>${admin.age} </td>
                <td>${admin.country} </td>
                <td>${admin.address} </td>
                <td>${admin.zipcode} </td>
                <td>${admin.Matrix1} </td>
                <td>${admin.Matrix2} </td>
                <td>${admin.Result} </td>
                <td>${admin.location} </td>
            </tr>


        </c:forEach>

    </table>

The stack error is:

javax.el.PropertyNotFoundException: Property 'firstName' not found on type matrixcalculator.administration
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:229)
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:206)
javax.el.BeanELResolver.property(BeanELResolver.java:317)
javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
org.apache.el.parser.AstValue.getValue(AstValue.java:182)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:967)
org.apache.jsp.showFullList_jsp._jspx_meth_c_005fforEach_005f0(showFullList_jsp.java:149)
org.apache.jsp.showFullList_jsp._jspService(showFullList_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:750)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:720)
org.apache.jsp.processInfo_jsp._jspService(processInfo_jsp.java:88)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

-Silvestrini

Upvotes: 0

Views: 358

Answers (2)

Neeraj Jain
Neeraj Jain

Reputation: 7720

javax.el.PropertyNotFoundException: Property 'firstName' not found on type matrixcalculator.administration

That just means that the given class doesn't have the following method:

public SomeObject getFirstName() {
    return firstName;

if this method is present then make sure signature is exactly the same it should be public and take no arguments

Update

Problem is Your getterName is not in camelCase whereas your variable name is in camelCase

public String getFirstname() {
    return firstName;
}

change it to

public String getFirstName() {  // N should be capital
    return firstName;
}

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 692231

The exception message is very clear:

Property 'firstName' not found on type matrixcalculator.administration

That means there is no method with the following signature in the class matrixcalculator.administration:

public String getFirstName()

Upvotes: 1

Related Questions