我的代码显示错误

时间:2016-06-30 17:20:56

标签: java mysql jsp jdbc

我的分页代码从html文件中获取页码的值,并显示来自sql数据库表的具有分页逻辑的特定页面。 我已经给出了代码,然后显示错误。请帮忙 提前谢谢!!

<%@ page contentType="text/html; charset=iso-8859-1" language="java"                         import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellpadding="0" cellspacing="0"      bgcolor="#CCCCCC">
    <tr bgcolor="#66FF99">
  <td>Sr.</td>
  <td>Name</td>
  <td>Cost</td>

</tr>




<%


int p= Integer.parseInt(request.getParameter("textfield"));
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/tiop","root","root");
Statement stat=con.createStatement();
ResultSet rs=stat.executeQuery("select * From (select * , Row_Number() over   (order by Sr) as RowNum From cre )T where T.RowNum between ((p-1)*5)+1
and (p*5)");

while(rs.next())
{



%>
<tr>
  <td bgcolor="#99CC33"><%=rs.getInt(1)%></td>
  <td bgcolor="#669966"><%=rs.getString(2)%></td>
  <td bgcolor="#FF3333"><%=rs.getInt(3)%></td>

</tr>

<%
}

%>
 </table>
</form>
</body>
</html>

显示错误:

HTTP Status 500 - Unable to compile class for JSP:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 29 in the jsp file: /pa.jsp
String literal is not properly closed by a double-quote
26: Class.forName("com.mysql.jdbc.Driver");
27: Connection con=DriverManager.getConnection("jdbc:mysql://localhost/tiop","root","root");
28: Statement stat=con.createStatement();
29: ResultSet rs=stat.executeQuery("select * From (select * , Row_Number() over (order by Sr) as RowNum From cre )T where T.RowNum between ((p-1)*5)+1
30: and (p*5)");
31: 
32: while(rs.next())


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:446)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.9 logs.

Apache Tomcat/8.0.9

1 个答案:

答案 0 :(得分:0)

无错误证明 proof of no-errors

解决方案:复制并粘贴以下内容: @Barranka也是对的

Customer A    201501     1200
Customer A    201510     4000
Customer B    201501     200

如果您无法将完整的String query = "select * From (select * , Row_Number() over (order by Sr) as RowNum From cre )T where T.RowNum between ((p-1)*5)+1 and (p*5)"; ResultSet rs = stat.executeQuery(query); 放在一行上。请执行以下操作:

select-query

问题出在哪里?

  

建议由StackTrace&#34; 字符串文字没有被双引号正确关闭&#34;

在以下行的ResultSet rs = stat.executeQuery("select * From (select * , Row_Number() over (order by Sr) as RowNum From cre )T where T.RowNum between ((p-1)*5)+1" + "add (p*5)"); 标记上。换行导致了这个问题。 XXX在下一行没有连接。

and (p*5)"

为简单起见:将查询存储在"select * From (select * , Row_Number() over (order by Sr) as RowNum From cre )T where T.RowNum between ((p-1)*5)+1 XXX and (p*5)" 中,连接多个查询,简化长查询并在查询执行中使用它们。此外,有助于重用该查询。