写数据库程序的时候每次进行数据库相关操作结束后都马上加句connection.close;关闭与数据库的连接。从来没有人说明这是个惯例,还是必须,所有的范例都是这么写,却都没有解释,保持数据库连接不是更好么?现代数据库不是都支持并行操作的?为什么还要这样。今天我有了自己的看法。
All the examples given up to this point in this chapter have closed the Connection object after the servlet services the request. However, you might ask the following question: If the servlet is called more than once and it opens a Connection object with the same arguments (url, user, and password) each time, wouldn’t it better to leave the Connection object open for future use; that is, for when the servlet is called again?
继续阅读“Should I Keep the Connection Open?”