我想从数据库中检索整个表并将其显示到我的jsp页面中,但我得到了一个错误
我的工作人员豆。java是
package com.staff.bean;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class StaffBean {
private String date;
private int workload;
private int hourId;
private int daysId;
private int staffId;
private String StaffName;
private String ActiveORInactive;
private String Stafftype;
private String subcode;
private boolean valid = false;
public String getdate() {
// DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
// Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // your template here
java.util.Date dateStr = null;
try {
dateStr = formatter.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java.sql.Date dateDB = new java.sql.Date(dateStr.getTime());
return formatter.format(dateDB);
}
public void setdate(String date){
this.date=date;
}
public int gethourId() {
return hourId;
}
public void sethourId(int hourId) {
this.hourId = hourId;
}
public int getdaysId() {
return daysId;
}
public void setdaysId(int daysId) {
this.daysId = daysId;
}
public int getworkload() {
return hourId;
}
public void setworkload(int workload) {
this.workload = workload;
}
public int getstaffId() {
return staffId;
}
public void setstaffId(int staffId) {
this.staffId = staffId;
}
public String getStaffName() {
return StaffName;
}
public void setStaffName(String StaffName) {
this.StaffName = StaffName;
}
public String ActiveORInactive() {
return ActiveORInactive;
}
public void setActiveORInactive(String ActiveORInactive) {
this.ActiveORInactive = ActiveORInactive;
}
public String getStafftype() {
return Stafftype;
}
public void setStafftype(String Stafftype) {
this.Stafftype = Stafftype;
}
public String getsubcode() {
return Stafftype;
}
public void setsubcode(String subcode) {
this.subcode = subcode;
}
public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}
}
而我的getAllDetailDAO.java是
package com.staff.DAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.staff.bean.StaffBean;
import com.staff.DB.ConnectionProvider;
public class GetAllDetailDAO {
Connection con;
Statement stmt;
private int noOfRecords;
public List<StaffBean> viewAllStaff(int offSet, int noOfRecords){
List<StaffBean> list = new ArrayList<StaffBean>();
StaffBean _staffBean;
try {
con = ConnectionProvider.getConnection();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select SQL_CALC_FOUND_ROWS * from tblstaffdetails limit "+offSet+","+noOfRecords);
//+offSet+","+noOfRecords);
//SQL_CALC_FOUND_ROWS
while(rs.next()){
_staffBean = new StaffBean();
_staffBean.setStaffName(rs.getString("StaffName"));
_staffBean.setstaffId(rs.getInt("staffId"));
_staffBean.setActiveORInactive(rs.getString("ActiveORInactive"));
_staffBean.setStafftype(rs.getString("Stafftype"));
list.add(_staffBean);
}
rs.close();
rs = stmt.executeQuery("SELECT FOUND_ROWS()");
if(rs.next())
this.noOfRecords = rs.getInt(1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public int getNoOfRecords() {
return noOfRecords;
}
}
连接提供程序包com.staff.db;
import java.sql.*;
public class ConnectionProvider {
static Connection con;
static String url;
public static Connection getConnection() throws SQLException{
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/StaffAllocation","root", "success");
}catch(ClassNotFoundException cnf){
cnf.printStackTrace();
}
return con;
}
}
package com.staff.servlet;
import java.io.IOException;
import java.util.List;
import java.sql.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.staff.bean.StaffBean;
import com.staff.DAO.GetAllDetailDAO;
import com.staff.DB.*;
@WebServlet("/GetAllDetailServlet")
public class GetAllDetailServlet extends HttpServlet{
/**
* Servlet implementation class GetAllDetailsServlet
*/
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GetAllDetailServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
int page = 1;
int recordsPerPage = 4;
if(request.getParameter("page") != null)
page = Integer.parseInt(request.getParameter("page"));
GetAllDetailDAO allDetailDAO = new GetAllDetailDAO();
List<StaffBean> list = allDetailDAO.viewAllStaff((page-1)*recordsPerPage, recordsPerPage);
int noOfRecords = allDetailDAO.getNoOfRecords();
int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage);
request.setAttribute("staffList", list);
request.setAttribute("noOfPages", noOfPages);
request.setAttribute("currentPage", page);
RequestDispatcher view = request.getRequestDispatcher("jsp/displayAllDetail.jsp");
view.forward(request, response);
}
}
而我的DisplayAllDetail.jsp是
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> :: All Details</title>
</head>
<body>
<fieldset>
<table border="1" cellpadding="4" cellspacing="4" align="center">
<tr>
<th>staffId</th>
<th>StaffName</th>
<th>ActiveORInactive</th>
<th>Stafftype</th>
<c:forEach var="_staffBean" items="${staffList}">
<tr>
<td>${_staffBean.staffId}</td>
<td>${_staffBean.StaffName}</td>
<td>${_staffBean.ActiveORInactive}</td>
<td>${_staffBean.Stafftype}</td>
</tr>
</c:forEach>
</tr>
</table>
<c:if test="${currentPage != 1}">
<td><a href="getAll.do?method=get&page=${currentPage - 1}">Prev</a></td>
</c:if>
<table border="1" cellpadding="5" cellspacing="5" align="center">
<tr>
<c:forEach begin="1" end="${noOfPages }" var="i">
<c:choose>
<c:when test="${currentPage eq i }">
<td>${i}</td>
</c:when>
<c:otherwise>
<td><a href="getAll.do?method=get&page=${i}">${i}</a></td>
</c:otherwise>
</c:choose>
</c:forEach>
</tr>
</table>
<c:if test="${currentPage lt noOfPages }">
<td><a href="getAll.do?method=get&page=${currentPage+1 }">Next</a></td>
</c:if>
</fieldset>
</body>
</html>
我的错误是
HTTP Status 500 - An exception occurred processing JSP page /jsp/displayAllDetail.jsp at line 22
type Exception report
message An exception occurred processing JSP page /jsp/displayAllDetail.jsp at line 22
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/displayAllDetail.jsp at line 22
19: <c:forEach var="_staffBean" items="${staffList}">
20: <tr>
21: <td>${_staffBean.staffId}</td>
22: <td>${_staffBean.StaffName}</td>
23: <td>${_staffBean.ActiveORInactive}</td>
24: <td>${_staffBean.Stafftype}</td>
25: </tr>
StackTrace:org.apache.jasper.servlet.jspServletwrapper.handleJSPException(jspServletwrapper.java:568)org.apache.jasper.servlet.jspServletwrapper.java:470)org.apache.jasper.server.jspServer.serviceJSPFile(jspServlet.java:390)org.apache.jasper.server.jspServer.service(jspServlet.java:334)javax.servet.http.httpservlet.service(httpservlet.java:728)
根本原因
javax.el.PropertyNotFoundException: Property 'StaffName' not found on type com.staff.bean.StaffBean
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
javax.el.BeanELResolver.property(BeanELResolver.java:325)
javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
org.apache.el.parser.AstValue.getValue(AstValue.java:183)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
org.apache.jsp.jsp.displayAllDetail_jsp._jspx_meth_c_005fforEach_005f0(displayAllDetail_jsp.java:157)
org.apache.jsp.jsp.displayAllDetail_jsp._jspService(displayAllDetail_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)
com.staff.servlet.GetAllDetailServlet.doGet(GetAllDetailServlet.java:56)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
注意,Apache Tomcat/7.0.42日志中提供了根本原因的完整堆栈跟踪。
private String staffName;
private String activeORInactive;
private String stafftype;
而不是用大写字母。
我建议您遵循Java代码转换
我正在两个标记之间画一条路线,我想保存那条路线。为此,我将包含lat和lng的ArrayList保存在Firebase数据库中。但我在取回航路点时遇到了问题。我是这样插入的: 在检索数据时,我尝试执行以下操作:
关于我的上一个问题,我想从创建的sqlite数据库中检索ID,将其作为Intent putExtra()中的数据传递,以便将其用作PendingContent的ID。getActivity()。目前,我正在使用queryNumEntries为从我的DatabaseManager中的以下代码添加到数据库中的每个提醒设置id。类别: 并在AddActivity中调用它。班 在创建条目时,除了尝试此操作
我想从数据库中检索名称。但我总是收到错误: 数据库Java语言 它不断返回错误 android.database.CursorIndexOutOfBoundsException:请求索引-1,大小为1,字符串名称=helper.getProductNameT(cur); 有人知道我的编码哪里出错了吗?
问题内容: 嗨,我已经成功地将jTable链接到JDBC数据库。但是,我在检索它们时遇到了麻烦。我希望在重新启动程序时出现保存的数据,但是它不起作用。 这是我保存文档的代码! 有什么方法可以检索JDBC数据库中的数据并通过Jtable显示它?我很抱歉提出这样一个简单的问题,但是我是Java新手,我非常需要帮助! 非常感谢! 用于加载数据的代码… 顺便说一句,我的jtable是一个3列的表,其中包含
我正在尝试实施一个工资系统,但我在更新员工方面遇到了一些问题。我已将员工的性别作为varchar存储在数据库中。当我输入员工id并单击搜索按钮时,我想从数据库中获取该信息,并根据数据以男性/女性单选按钮显示。代码中没有错误。但问题是,当我尝试这样做时,只有男性按钮显示为选中状态,这是默认设置。即使数据库上的数据显示为女性,女性单选按钮也不会被选中。有谁能帮我解决这个问题吗?下面是我的代码。
我有一个名为employee_comp_field的表,其中提供了薪资字段 然后,我有另一个表,其中员工工资数据存储emp_compensation每个字段。正如你所看到的emp_id 10有三套记录,因为他在同一年获得了三次加薪(year_id=101),这可以通过salary_order领域来识别。 我想用最大工资确定所有雇员的名单,我的期望输出如下: emp_id10号得到了三次加薪……所以