请帮忙看一下一下代码为什么提示以下错误Unable to compile class for JSP

qq_40545642 2017-11-06 03:30:40
<%@ page language="java" contentType="text/html; charset=GB2312"%>
<%@ page import="java.sql.*,java.io.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>pages</title>
</head>
<body>

<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int totalcount = 0;
int totalpages = 0;
try{
//A.注册驱动
Driver driver = new com.mysql.jdbc.Driver();//此处报错,An error occurred at line: 19 in the jsp file: /page.jsp
com.mysql.jdbc.Driver cannot be resolved to a type

DriverManager.registerDriver(driver);
//B.获取数据库连接
String url ="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GB2312&useSSL=false";
String user = "root";
String password = "123";
conn = DriverManager.getConnection(url, user, password);
//C.获取数据库操作对象
stmt = conn.createStatement();
/*
实现SQL结果集分页功能
*/
//D.执行SQL语句
//1.获得总的记录数TotalCount
String sql = "select * from student ";
rs = stmt.executeQuery(sql);
while(rs.next()){
totalcount = rs.getInt("id");
}
System.out.println(totalcount);


}catch(Exception e){

e.printStackTrace();

}finally{
if(rs != null){
try{

rs.close();

}catch(Exception e){

e.printStackTrace();
}
}

if(stmt != null){
try{

stmt.close();

}catch(Exception e){

e.printStackTrace();
}
}

if(conn != null){
try{

conn.close();

}catch(Exception e){

e.printStackTrace();
}
}
}
%>
</body>
</html>
...全文
210 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xwn_2016 2017-11-07
limit后边不支持表达式吧
  • 打赏
  • 举报
回复
半城煙沙 2017-11-07
tomcat,jdk jar包没引用到。
  • 打赏
  • 举报
回复
qq_40545642 2017-11-06
<%@ page language="java" contentType="text/html; charset=GB2312"%> <%@ page import="java.sql.*,java.io.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>pages</title> </head> <body> <% Connection conn = null; Statement stmt = null; ResultSet rs = null; int totalcount = 0; int totalpages = 0; int currentpage = 1; try{ //A.注册驱动 Driver driver = new com.mysql.jdbc.Driver(); DriverManager.registerDriver(driver); //B.获取数据库连接 String url ="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GB2312&useSSL=false"; String user = "root"; String password = "280613"; conn = DriverManager.getConnection(url, user, password); //C.获取数据库操作对象 stmt = conn.createStatement(); %> <%--实现SQL结果集分页功能,一页显示3个数据 --%> <% //1.获得总的记录数TotalCount String sql = "select * from student "; rs = stmt.executeQuery(sql); while(rs.next()){ totalcount = rs.getInt("id"); } totalpages =(totalcount%3 == 0)?(totalcount/3):(totalcount/3+1); System.out.println(totalpages); %> <% String s = "select id,name,score,age,password from student limit (currentpage-1)*3,3"; //再帮我看一下这个地方为什么会报错 rs = stmt.executeQuery(s); %> <%-- 显示页码签 --%> 页码: <% for(int i=1;i<=totalpages;i++){ if(i == currentpage){ %> <%=i%> <% }else{ %> <a href="page.jsp?currentpage=<%=i%>"><%=i %></a> <% } } %> <%-- 显示当前页面的记录 --%> <table border="1" width=300> <tr> <td>工号</td> <td>姓名</td> <td>学科成绩</td> <td>年龄</td> <td>登陆密码</td> </tr> <% while(rs.next()){ int id = rs.getInt("id"); String num = rs.getString("num"); String name = rs.getString("name"); Double score = rs.getDouble("score"); int age = rs.getInt("age"); String passwords = rs.getString("password"); %> <tr> <td><%=id %></td> <td><%=name %></td> <td><%=score %></td> <td><%=age %></td> <td><%=passwords %></td> </tr> <% } %> </table> <% }catch(Exception e){ e.printStackTrace(); }finally{ if(rs != null){ try{ rs.close(); }catch(Exception e){ e.printStackTrace(); } } if(stmt != null){ try{ stmt.close(); }catch(Exception e){ e.printStackTrace(); } } if(conn != null){ try{ conn.close(); }catch(Exception e){ e.printStackTrace(); } } } %> </body> </html>
  • 打赏
  • 举报
回复
uMonster 2017-11-06
未在WEB-INF的lib目录下添加相应的JDBC的jar包,然后导入项目中。其次在stmt.close();后面加stmt = null; 这样写更好更规范一点!
  • 打赏
  • 举报
回复
qq_40545642 2017-11-06
未在web-inf的lib目录下添加jar包
  • 打赏
  • 举报
回复
发帖
Web 开发

8.0w+

社区成员

Java Web 开发
社区管理员
  • Web 开发社区
加入社区
帖子事件
创建了帖子
2017-11-06 03:30
社区公告
暂无公告