0

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

Silvestrini
  • 335
  • 3
  • 17
  • Please tell us from which line the null pointer exception came from.. – O. Jones Feb 15 '15 at 13:12
  • @ Ollie Jones the problem starts when trying to display the firstName. Note this is on the JSP that happens. I get the username and password but from firstName and down I get the null pointer exception. I'll edit the code to show the JSP. EDITED TO SHOW JSP – Silvestrini Feb 15 '15 at 13:14
  • @Silvestrini When you ask about an exception, ALWAYS post the complete stack trace of the exception. Read http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it – JB Nizet Feb 15 '15 at 13:17
  • @ JB Nizet by the complete stack trace you mean the error? – Silvestrini Feb 15 '15 at 13:18
  • http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors – JB Nizet Feb 15 '15 at 13:19
  • I had a clue it was that, I posted the stack trace! – Silvestrini Feb 15 '15 at 13:22

2 Answers2

1

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()
JB Nizet
  • 633,450
  • 80
  • 1,108
  • 1,174
  • I do have all the gets and sets methods for every attribute declared in my class. Do you mean I have to call it explicitly? – Silvestrini Feb 15 '15 at 13:26
  • No, I mean you don't have it. Where is the code to prove it? Post it in your question. – JB Nizet Feb 15 '15 at 13:27
  • Yes. And indeed, you don't have it. The case matters: your method is named `getFirstname`. And you're accessing the property `firstName`. `n != N`. – JB Nizet Feb 15 '15 at 13:35
  • I edited and now I get same error at Matrix1. :S I dont see the difference there... – Silvestrini Feb 15 '15 at 13:38
  • Once again. If the getter is `getMatrix1()`, then the property name is `matrix1`, not `Matrix1`. if the getter is `getFooBarBaz()`, the property is `fooBarBaz`. Properties always start with a lowercase letter, just as Java variables. – JB Nizet Feb 15 '15 at 13:40
  • Just to be clear, the word that follows the "get" must ALWAYS be lower case? – Silvestrini Feb 15 '15 at 13:41
  • NOOOO. Read my comments correctly. I said: if your getter is named `getFooBarBaz()`, then the corresponding property name, used in the JSP EL expressions, is `fooBarBaz`. The first letter after `get` is uppercase. The first letter of the property is lowercase. property `fooBarBaz` <==> getter `getFooBarBaz()`. – JB Nizet Feb 15 '15 at 13:43
  • Ohhh hahaha okay I get it now. Property first letter ALWAYS lowercase so JSP knows what it is. Is that what you meant? – Silvestrini Feb 15 '15 at 13:46
  • Thank you for your time and patience. Its working now! – Silvestrini Feb 15 '15 at 13:53
1

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;
}
Neeraj Jain
  • 7,077
  • 3
  • 26
  • 53