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

6
  • Please tell us from which line the null pointer exception came from.. Commented Feb 15, 2015 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 Commented Feb 15, 2015 at 13:14
  • @Silvestrini When you ask about an exception, ALWAYS post the complete stack trace of the exception. Read stackoverflow.com/questions/218384/… Commented Feb 15, 2015 at 13:17
  • @ JB Nizet by the complete stack trace you mean the error? Commented Feb 15, 2015 at 13:18
  • stackoverflow.com/questions/3988788/… Commented Feb 15, 2015 at 13:19

2 Answers 2

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()
Sign up to request clarification or add additional context in comments.

8 Comments

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?
No, I mean you don't have it. Where is the code to prove it? Post it in your question.
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.
I edited and now I get same error at Matrix1. :S I dont see the difference there...
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.
|
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;
}

7 Comments

Edited the question, posted all the sets and gets!
you are using getFirstname it should be getFirstName
Ahhhh I see it must be literally the same as the DataBase column names? Now I get the same error at Matrix1?
@Silvestrini the database column name is irrelevant. Your JSP is getting data from a Java Bean. Not from the database. What matters is the Java Beans conventions.
@Silvestrini you should keep you variable name as matrix1 and in jsp use ${admin.matrix1} , i suugest you to please read that link i have provided in my answer
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.