Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    College Station. TX
    Posts
    4

    Unanswered: Need help with an error when connecting to an Access db

    When the following method runs I get a error that says:

    Exception occurred during event dispatching:
    java.lang.NullPointerException
    (and then a bunch of lines)

    The weird thing is that I can connect to the database fine when using other methods in this class, but for some reason this one gives me the above error. Also, if I get a resultset from another method and then come back and run this method it won't give the error, but it also doesn't give the expected resutls. What is going on here?

    public static Vector find (String searchText, String searchMethod)
    {
    aLargeAnimal = null;
    if (searchMethod.equals("Animal Name"))
    {
    String sqlStatement = "SELECT petName, animalType, diagnosis, annualVaccinationDate " +
    "FROM LargeAnimal " +
    "WHERE petName = '" + searchText + "'";

    System.out.println(sqlStatement);
    try
    {

    ResultSet rs2 = aStatement.executeQuery(sqlStatement);

    boolean isMoreData = rs2.next();

    while(isMoreData)
    {
    System.out.println("1");
    aPetName = rs2.getString(1);
    anAnimalType = rs2.getString(2);
    aDiagnosis = rs2.getString(3);
    anAnnualVaccinationDate = parseFormat.parse(rs2.getString(4));


    aLargeAnimal = new LargeAnimal(aPetName, anAnimalType, aDiagnosis, anAnnualVaccinationDate);
    largeAnimals.addElement(aLargeAnimal);
    isMoreData = rs2.next();

    }

    rs2.close();
    aStatement.close();
    }
    catch(SQLException sql)
    {
    System.out.println(sql);
    }
    catch(ParseException parse)
    {
    System.out.println(parse);
    }
    }
    else
    // rest of code here
    return largeAnimals;
    }

  2. #2
    Join Date
    Nov 2003
    Location
    College Station. TX
    Posts
    4
    Oh yeah, I also have pretty much narrowed the error down to a problem with the statement 'ResultSet rs2 = aStatement.executeQuery(sqlStatement);', but I have no clue what is wrong with it.

  3. #3
    Join Date
    Nov 2003
    Location
    College Station. TX
    Posts
    4
    OK, I solved that problem....dumb mistake. Now I have another: is there any way to clear a ResultSet?? It seems to keep records from past SQL Select statements. So how do you clear it?

  4. #4
    Join Date
    Nov 2003
    Location
    College Station. TX
    Posts
    4
    Problem solved.........

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •