简体   繁体   中英

Does the SQL Server JDBC driver support asynchronous operations?

From some googling, it appears that .NET supports asynchronous operations with SQL Server 2005+. Does the latest JDBC driver support this? I can't find a mention of it anywhere, so I'm thinking it probably doesn't. But I figured it couldn't hurt to ask.

Thanks! Avi

No, but that doesn't mean you can't do asynch database operations. You'd just put the asynch character in an appropriate layer, like a message driven bean or a Process thread. I don't see why JDBC should have to support a middle tier notion like asynch processing.

JDBC is pretty much all single threaded. From Connection down it is expected only one thread will use it for it's lifetime (ok Connections can get pooled but that should be invisible to the application and only one thread should be using a Connection at a time).

There is one exception which is Statement.cancel() which permits another thread to interrupt/cancel an in-progress query but I believe this is the only instance of multi-threaded-ness.

Like duffymo says typically if you want async behaviour you would build something on top of JDBC (and I would guess that's what .NET is doing under the covers).

The commons-dbutils library provides a nice wrapper around JDBC calls and even provides an asynchronous way of making calls: AsyncQueryRunner . Worth a look: http://commons.apache.org/dbutils/apidocs/org/apache/commons/dbutils/AsyncQueryRunner.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM