INNER CODE UNIT · Java
findDogById
righettod/poc-graphql · src/main/java/eu/righettod/graphqlpoc/repository/BusinessDataRepository.java:172
public Dog findDogById(int dogId) throws Exception {
Dog d = null;
String sql = "SELECT ID, NAME, VETERINARY_ID FROM DOG WHERE ID = ?";
try (PreparedStatement stmt = this.storageConnection.prepareStatement(sql)) {
stmt.setInt(1, dogId);
try (ResultSet rst = stmt.executeQuery()) {
while (rst.next()) {
d = new Dog(rst.getInt("ID"), rst.getString("NAME"), this.findVeterinaryById(rst.getInt("VETERINARY_ID")));
}
}
}
return d;
}
/**
* Associated a dog to a veterinary if the dog is free
*
* @param veterinaryId Veterinary ID