Announcement Announcement Module
Collapse
No announcement yet.
petclinic sql select statements having 2 or more variables Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • petclinic sql select statements having 2 or more variables

    A real newbie here.

    From the petclinic example how does one use two (not only one) variables in the where clause of a select statement. I'm using JDBC with Mysql.

    I can't get the following to run.

    public Collection findOwners(String lastName) throws DataAccessException {
    List owners = this.ownersByNameQuery.execute(lastName + "%" , 6);
    loadOwnersPetsAndVisits(owners);
    return owners;
    }

    protected class OwnersByNameQuery extends OwnersQuery {

    /* Create a new instance of OwnersByNameQuery.
    * @param ds the DataSource to use for the query
    */

    protected OwnersByNameQuery(DataSource ds) {
    super(ds, "SELECT id ,first_name,last_name,address,city,telephone,email ,pw FROM owners WHERE last_name like ? and id < ?");
    declareParameter(new SqlParameter(Types.VARCHAR));
    declareParameter(new SqlParameter(Types.INTEGER));
    compile();
    }

    I added the second parameter declaration.

    Thanks much,

    Craig

  • #2
    I suppose your code doesn't compile, right ?

    OwnersByNameQuery inherits a lot of overloaded execute() methods from SqlQuery (taking 1 int, taking 2 ints, taking 1 string, ...)
    but the version you try to call (one string and one int) doesn't exist.

    Try this:
    Code:
    Object params&#91;&#93; = &#123; lastname + "%" , new Integer&#40;6&#41; &#125;;
    List owners = this.ownersByNameQuery.execute&#40;params&#41;;
    HTH
    Maarten

    Comment


    • #3
      That solved it simply enough.

      Thanks for the response.
      Craig

      Comment

      Working...
      X