Configure hibernate to connect to database via JNDI Datasource

Apparently, you did it right. But here is a list of things you’ll need with examples from a working application: 1) A context.xml file in META-INF, specifying your data source: <Context> <Resource name=”jdbc/DsWebAppDB” auth=”Container” type=”javax.sql.DataSource” username=”sa” password=”” driverClassName=”org.h2.Driver” url=”jdbc:h2:mem:target/test/db/h2/hibernate” maxActive=”8″ maxIdle=”4″/> </Context> 2) web.xml which tells the container that you are using this resource: <resource-env-ref> … Read more

What does sp_reset_connection do?

Data access API’s layers like ODBC, OLE-DB and SqlClient call the (internal) stored procedure sp_reset_connection when re-using a connection from a connection pool. It does this to reset the state of the connection before it gets re-used. There does not appear to be official documentation on what things get reset, but here is an unofficial … Read more

Where do I have to place the JDBC driver for Tomcat’s connection pool?

The JDBC driver has to be visible to the same classloader as the data source factory itself. The data source factory library is placed in Tomcat’s own /lib folder and thus loaded by Tomcat’s “common” classloader. Your problem sounds much like that you dropped the JDBC driver in webapp’s /WEB-INF/lib. The webapp’s /WEB-INF/lib is invisible … Read more

Why doesn’t Dapper dot net open and close the connection itself?

Dapper now (and for quite some time) deals with this internally. It just works™ Original (outdated) answer: You aren’t wrong. The reason I hadn’t noticed this inconvenience is that for legacy reasons (specifically: we used to use LINQ-to-SQL exclusively) our primary connection-like-thing is a DataContext – so we re-expose the dapper methods as extension methods … Read more

Spring JDBC connection pool best practices

C3PO and DBCP development have stalled mostly because they are mature. I have seen both of these drivers be able to support hundreds of transactions per second. The Tomcat pool is a reworked & updated DBCP driver. MyBatis 3.0 also contains it’s own pooling implementation which, based on code inspection, seems solid. Finally, there’s BoneCP … Read more

What is the best solution for database connection pooling in python?

In MySQL? I’d say don’t bother with the connection pooling. They’re often a source of trouble and with MySQL they’re not going to bring you the performance advantage you’re hoping for. This road may be a lot of effort to follow–politically–because there’s so much best practices hand waving and textbook verbiage in this space about … Read more

Is the Session object from Python’s Requests library thread safe?

After reviewing the source of requests.session, I’m going to say the session object might be thread-safe, depending on the implementation of CookieJar being used. Session.prepare_request reads from self.cookies, and Session.send calls extract_cookies_to_jar(self.cookies, …), and that calls jar.extract_cookies(…) (jar being self.cookies in this case). The source for Python 2.7’s cookielib acquires a lock (threading.RLock) while it … Read more