I don't know any API that do that
there are some JDO implementations that support cancel in some special databases, but I don't know any standard way that works on all databases.
usually it is either a local DB and local driver, then queries usually block the program execution so you can't cancel.
if DB is on another machine, or connected through network layer the best you can is ignoring the wait for DB response in most cases.