Javascript Java—使用“find”命令显示或删除access文件中的特定记录

Javascript Java—使用“find”命令显示或删除access文件中的特定记录,javascript,sql,database,Javascript,Sql,Database,所以我一直很难让这个Java代码正常工作。我正在尝试使用find函数从access数据库文件.accdb中查找一组特定的信息,并显示或删除它 我运气不太好。这是令人费解的,就我所知,在向数据库添加新条目时还需要find代码,我可以毫无问题地完成这项工作。坦白说,我怀疑我在什么地方贴错了标签 下面是我的代码片段,它还显示了一个查找由用户写入文本框的密钥标识的特定文件的示例。如能帮助解决此问题,将不胜感激 // Implement the four instance methods ********

所以我一直很难让这个Java代码正常工作。我正在尝试使用find函数从access数据库文件.accdb中查找一组特定的信息,并显示或删除它

我运气不太好。这是令人费解的,就我所知,在向数据库添加新条目时还需要find代码,我可以毫无问题地完成这项工作。坦白说,我怀疑我在什么地方贴错了标签

下面是我的代码片段,它还显示了一个查找由用户写入文本框的密钥标识的特定文件的示例。如能帮助解决此问题,将不胜感激

// Implement the four instance methods *************
    // addNew, delete, update - called from each specific PD class
    // find - used locally by addNew(), delete(), and update().
    /**
     * An instance method to find a record in the database.<br /><br />
     *
     * This is a private method and can only be used locally within objects instantiated from this class.<br />
     * Used by addNew(), delete(), and update().
     *
     * @param String objectType
     * @param String key
     * @return a Anime object
     * @throws NotFoundException
     * @throws SQLException
     */
    private Anime find (String objectType, String key) throws NotFoundException, SQLException {

        anAnime = null;

        if (objectType.equalsIgnoreCase ("PlushToys")) {
                // define the SQL query statement using the phone number key
            String sqlQuery = "SELECT Anime, Character, Ability, CanItSpeak, Material, Size " +
                                "FROM PlushToys" +
                                "Where Character = '" + key +"'";

                // execute the SQL query statement
            ResultSet rs = aStatement.executeQuery (sqlQuery);

                // next method sets cursor & returns true if there is data
            boolean gotIt = rs.next();
            if (gotIt) {
                // extract the data
            String Anime = rs.getString(1);
            String Character = rs.getString (2);
            String Ability = rs.getString (3);
            String CanItSpeak = rs.getString (4);
            String Material = rs.getString (5);
            String Size = rs.getString (6);
                // create PlushToy instance & add it to the ArrayList
            anAnime = new PlushToys (Anime, Character, Ability, CanItSpeak, Material, Size);
                rs.close();
            } else {
                    // nothing was retrieved
                rs.close();
                throw (new NotFoundException ("not found "));
            }

SQL查询之后,您需要询问结果是否为空。因此,您必须计算结果中的行数。您可以通过以下方式实现:

ResultSet rs;
  ...
  int count = 0;
  while(rs.next()) {
    count++;  

  }
当count为零时,结果中就没有条目,用户搜索的内容不在数据库中