DbUtils用过后怎么关闭

网友 2

最佳答案

回答者:网友
这个得要程序配合啊,如果获取了Connection之后,得手动关闭啊,我以前用实例验证过,获得Connection之后,用proxool连接池看到的链接确实没有释放掉。 刚才看了下,官网上的例子,有这么一段: ResultSetHandler h = ... // Define a handler the same as above example // No DataSource so we must handle Connections manually QueryRunner run = new QueryRunner(); Connection conn = ... // open a connection try{ Object[] result = run.query( conn, "SELECT * FROM Person WHERE name=?", h, "John Doe"); // do something with the result } finally { // Use this helper method so we don't have to check for null DbUtils.close(conn); }

回答

其他回答
ResultSetHandler < Object []> h = ... // Define a handler the same as above example // No DataSource so we must handle Connections manually QueryRunner run = new QueryRunner (); Connection conn = ... // open a connection try { Object [] result = run . query ( conn , "SELECT * FROM Person WHERE name=?" , h , "John Doe" ); // do something with the result } finally { // Use this helper method so we don't have to check for null DbUtils . close ( conn ); }
回答者:网友
我来回答