JSP页面出错 - org.apache.jasper.JasperException

时间:2017-10-15 16:43:05

标签: java mysql jsp

    <%@ page import = "java.sql.*" %>
<!-- Variables Declaration -->
<%! 
String connectionURL = "jdbc:mysql://localhost:3306/Tamir";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>

<!-- Connecting to database "Tamir" -->
<%!
void ConnectDb(){
    try{
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        connection = DriverManager.getConnection(connectionURL,"root","tamir");
        statement = connection.createStatement();
    } catch (Exception ex){
        System.out.print("Error in connecting");
    }
}
%>
<!-- Html Part Starts Here -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1255">
<title> Test Database </title>
</head>
<body>

<h1> test hello </h1>
<%
ConnectDb();
rs = statement.executeQuery("SELECT * FROM users");
out.println(rs.getString("nickname"));
rs.close();
%>

</body>
</html>

收到错误: error 是的,我在web-inf的lib中有mysql连接器。

是的我有一个名为Tamir和密码tamir的数据库,以及表Users;

是的,我已经安装并运行了tomcat。

我已经在互联网上寻找了很长时间,帮助将是适当的。欢呼声。

编辑:完整错误如下:

HTTP Status 500 - An exception occurred processing JSP page /select.jsp at line 34


type Exception report

message An exception occurred processing JSP page /select.jsp at line 34

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 /select.jsp at line 34

31: <%
32: ConnectDb();
33: rs = statement.executeQuery("SELECT * FROM users");
34: out.println(rs.getString("nickname"));
35: rs.close();
36: %>
37: 


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    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)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)



root cause 
javax.servlet.ServletException: java.sql.SQLException: Before start of result set
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
    org.apache.jsp.select_jsp._jspService(select_jsp.java:110)
    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)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)



root cause 
java.sql.SQLException: Before start of result set
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
    com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:790)
    com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5212)
    com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5135)
    com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5174)
    org.apache.jsp.select_jsp._jspService(select_jsp.java:98)
    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)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)



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


Apache Tomcat/7.0.47
    enter code here

0 个答案:

没有答案