我需要选择借阅日期和退货日期它显示在这个价值日期之间我该怎么做才能帮我解决它上面的错误..
// String status1 = request.getParameter("status1");
// String com=" 1 = 1";
// get connection
Connection con = lm.Database.getConnection();
PreparedStatement ps=null;
ResultSet rs=null;
String bdate=request.getParameter("bdate");
String rdate=request.getParameter("rdate");
//Statement st = con.createStatement();
//ResultSet rs=ps.executeQuery("select * from issues where mid = ?");
String query = "select * from issues where bdate= '?' and rdate='?'";
ps.setString(1, bdate);
ps.setString(2,rdate);
ps = con.prepareStatement(query);
rs = ps.executeQuery();
System.out.println("query=="+rs);
// ResultSet rs = st.executeQuery("select * from issues where mid = " + mid);
// System.out.println("query=="+query);
//PreparedStatement ps=con.prepareStatement("select * from issues where = ?");
if (! rs.next())
{
//out.println("<h4>Sorry! Record Not Found!</h4>");
out.println("<p/> <a href='javascript:history.back()'>Back</a>");
return;
}
当我在页面上方跑时
我得到这样的错误..
An exception occurred processing JSP page /LRapplication/pages/search_dues.jsp at line 86
83: //ResultSet rs=ps.executeQuery("select * from issues where mid = ?");
84:
85: String query = "select * from issues where bdate= '?' and rdate='?'";
86: ps.setString(1, bdate);
87: ps.setString(2,rdate);
88: ps = con.prepareStatement(query);
89:
Stacktrace:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:428)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at org.apache.jsp.LRapplication.pages.search_005fdues_jsp._jspService(search_005fdues_jsp.java:163)
感谢您提前...注意:我在Java文件而不是Java类中编写Java代码,对于那些不相关的HTML噪音感到抱歉。
答案 0 :(得分:0)
PreparedStatement ps=null;
ps.setString(1, bdate);
ps.setString(2,rdate);
ps = con.prepareStatement(query);
在您分享之前,您无法访问 ps - 这就是您收到错误的原因,它仍为空。
移动ps = con.prepareStatement(query);
行。
有关如何使用PreparedStatement的更多信息:
http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html