错误信息:Description Location Resource Path Type
The method showCrane() is undefined for the type Query line 45 ShowAllCranesServlet.java /jsp_jdbc/src/com/cn/query Java Problem
在网上查了一些资料,依旧没有解决,有说要把JDK放在J2EE上面,依然无法解决,求教大神。非常感谢~
调用函数showCrane()的源代码:
package com.cn.query;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.management.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.cn.add.AddCrane;
import com.cn.vo.UserVo;
//这里省略部分无关代码
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//声明一个List对象
List list = new ArrayList();
Query query = new Query(); //声明一个Query类对象
list = query.showCrane(); //调用查询方法,把查询到的数据放入list对象中
request.setAttribute("list", list); //把list集合放入request对象中
request.getRequestDispatcher("showAllCranes.jsp").forward(request, response); //转发到实现数据的页面中
out.flush();
out.close();
}
定义showCrane()的源代码:
public List showCrane(){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
List list = new ArrayList(); //声明一个LIst集合,用于存放查询出的数据
try {
conn = JDBC_Connection.getConnection(); //连接数据库
stmt = conn.createStatement(); //建立Statement对象
rs = stmt.executeQuery("select * from cranes");
while (rs.next()){
UserVo userVo = new UserVo();
userVo.setApparatus_name(rs.getInt("apparatus_name"));
list.add(userVo); //把每次获得的对象数据放入list集合中
}
}catch (Exception e) {
//TODO Auto-generated catch block
e.printStackTrace();
} finally{
JDBC_Connection.free(rs,conn,stmt); //关闭连接
}
return list;
}