gpt4 book ai didi

java - 从数据库获取行数据到 JSP

转载 作者:行者123 更新时间:2023-11-29 07:43:02 24 4
gpt4 key购买 nike

我正在尝试使用联接显示数据库中的数据。我设法显示第一个表,但在尝试显示其他数据时出现空异常错误。我通过 Java 类来做到这一点。

这是函数...

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;
}

这是集合和获取:

 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;
}

我在 JSP 中使用迭代进行显示。您需要任何额外信息只需询问!我会看看我自己是否能找到错误。另外,我对庞大的查询语句表示歉意,它是作业的一部分,也是必需的。

JSP代码:

<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>

堆栈错误是:

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)

-西尔维斯特里尼

最佳答案

异常信息非常清楚:

Property 'firstName' not found on type matrixcalculator.administration

这意味着matrixcalculator.administration类中没有具有以下签名的方法:

public String getFirstName()

关于java - 从数据库获取行数据到 JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28526260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com