weixin_61938689 2022-09-27 11:13 采纳率: 50%
浏览 39

用MyEclipse Tomcat运行Statement stmt=conn.createStatement();出错怎么解决

问题遇到的现象和发生背景

应该是 Statement stmt=conn.createStatement();这句代码有错,但是不知道怎么改

用代码块功能插入代码,请勿粘贴截图
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<jsp:useBean id="DBConn" class="conn.DBConnAccess" scope="request"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'checkuser.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    

  </head>
  
  <body>
    <%
        request.setCharacterEncoding("utf-8");
        String username=request.getParameter("loginName");
        String password=request.getParameter("password");
        String checkcode=request.getParameter("checkcode");
        String piccode=request.getSession().getAttribute("piccode").toString();
        String role=request.getParameter("role");
        String dbpath=request.getRealPath("/")+"DB.accdb";
        Connection conn=DBConn.getConnToAccess(dbpath);
        Statement stmt=conn.createStatement();
        String sql="select * from userinfo";
        sql+="where loginname='"+username+"'and password='"+password+"' and role='"+role+"'";
         ResultSet rs=stmt.executeQuery(sql);
         if(checkcode.equals(piccode)&&rs.next())
         {
              session.setAttribute("userName",username);
              if(role.equals("admin"))
              {
              response.sendRedirect("admin/main.jsp");
              }
              else if(role.equals("client"))
              {
              response.sendRedirect("client/main.jsp");
              }
              }
         else{
             response.sendRedirect("login.jsp");
         }
 %>
     
  </body>
</html>



运行结果及报错内容

HTTP Status 500 -


type Exception report

message

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 /checkUser.jsp at line 36

33: String role=request.getParameter("role");
34: String dbpath=request.getRealPath("/")+"DB.accdb";
35: Connection conn=DBConn.getConnToAccess(dbpath);
36: java.sql.Statement stmt=conn.createStatement();
37: String sql="select * from userinfo";
38: sql+="where loginname='"+username+"'and password='"+password+"' and role='"+role+"'";
39: ResultSet rs=stmt.executeQuery(sql);

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.NullPointerException
org.apache.jsp.checkUser_jsp._jspService(checkUser_jsp.java:103)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.


Apache Tomcat/6.0.13

我的解答思路和尝试过的方法

将 Statement stmt=conn.createStatement(); 改为
java.sql.Statement stmt=conn.createStatement(); 但是还是不行 【!我是用MyEclipse Tomcat运行的!】

我想要达到的结果

希望可以正常运行,谢谢大家

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 创建了问题 9月27日

      悬赏问题

      • ¥15 求C++ I/O程序的编写示例
      • ¥15 openresty根据post请求体转发
      • ¥15 quartusⅡ18.1 这张图片的引脚绑定,实验箱如何操作,拍照回答,希望自己能够多学习点东西,让我进步,在以后会更好的使用这款软件,设计更多的程序
      • ¥15 Rstudio Cloud 无法读取本地文件怎么处理
      • ¥15 想要吧栈里面存储的数据写入到文件中
      • ¥15 fpga逻辑与代码不符合的问题
      • ¥15 Android studio安装后运行项目报错
      • ¥15 QGIS插件库不可用
      • ¥15 cisco asa防火墙固件上传出错?
      • ¥15 mescroll-uni的bug,上拉后再下拉导致问题