我刚开始尝试写jsp,我写了一个javabean用于查询数据库代码如下:   package javabean;
  import java.sql.*;   public class ConectBean{
          private String conndriver="sun.jdbc.odbc.JdbcOdbcDriver";
          private String conntarget="jdbc:odbc:Northwind";
          private Connection myConn;
  private int cols;
//建立数据库连接方法
     public void Conect()throws SQLException,Exception {
  
             //加载驱动程序
             Class.forName(this.conndriver).newInstance();             //建立连接
             this.myConn=DriverManager.getConnection(this.conntarget);
      }
    
//执行查询方法
public   ResultSet query(String querystr) throws SQLException{
              String queryString=querystr;
  Statement myStmt = this.myConn.createStatement();                   //执行查询
                  ResultSet myResults = myStmt.executeQuery(queryString);
              //首先得到查询结果的信息
                  ResultSetMetaData resultsMetaData = myResults.getMetaData();
                  //得到记录的条数
  this.cols = resultsMetaData.getColumnCount();
  
  //返回查询结果
  myResults.close();
                  myStmt.close();
                  this.myConn.close();
  return myResults;
  
    }
 
 
     public void setconndriver (String driver){ this.conndriver=driver;}
    public void setconntarget (String target){this.conntarget=target;}
   
    public String getconndriver(){ return this.conndriver;}
    public String getconntarget(){ return this.conntarget;}
public int getcols(){return this.cols;}
  }
我的jsp文件代码如下:
<jsp:useBean id="conn" scope="page" class="javabean.ConectBean" />
<%@ page import="java.sql.*"%>
<% String driver,select;
   int cols;
   conn.Conect();
   ResultSet results=conn.query("select * from Customers");//一执行这个查询方法就会出错!
   
%>错误提示如下:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: javabean.ConectBean.query(Ljava/lang/String;)Ljava/sql/ResultSet;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.conn.index_jsp._jspService(index_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause java.lang.NoSuchMethodError: javabean.ConectBean.query(Ljava/lang/String;)Ljava/sql/ResultSet;
org.apache.jsp.conn.index_jsp._jspService(index_jsp.java:53)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.请教大家是怎么回事!

解决方案 »

  1.   

     ResultSet results=conn.query("select * from Customers");//一执行这个查询方法就会出错! ======================
    conn.query() - -|、有這個方法么
    要么conn.executequery()要么conn.updatequery()
    直接query他不報錯么?
      

  2.   

    楼上的朋友query()是我在javabean里定义的方法.具体的查询细节封装在这个方法里了.conn是我引用这个bean的ID 
      

  3.   

    javabean.ConectBean.query
    没有这个方法。你确认你编译了那个ConectBean 最新版了吗?
      

  4.   

    我的ConectBean编译通过了呀,我用这个方法写了一个j2se的小程序都把数据结果给查出来了!
      

  5.   

    query 这个方法是我在ConectBean里自己写的查询方法!ConectBean是我自己手工写的一个bean
      

  6.   

     
      //返回查询结果 
      myResults.close(); 
      myStmt.close(); 
      this.myConn.close(); 
      return myResults; 

    这里怎么关闭了myResults,又在返回myResults?