My Software,My Dream—Forge a more perfect NMS product.
原來Statement stmt = conn.createStatement();都是在放在BaseDao中, 子類dao的方法中就可以直接用這個stmt,而且方法最后都會用finally 來close這個stmt以及rs。
這個做不好,因為new一個dao后,不能連續(xù)調(diào)用兩個方法,因為前一個方法 已經(jīng)把stmt關(guān)閉掉了。
因此新架構(gòu)中,在每個方法中都加入Statement stmt = conn.createStatement(); 這樣就不會有上述問題了,但以增加代碼量為代價。 例子:
Statement stmt = conn.createStatement()置于方法內(nèi),那么我們要這樣寫:
MenuDao mDao = new MenuDao(conn);
MenuDto menu = mDao.getNextMenu(dto.getId().substring(0,2));
MenuDao mDao2 = new MenuDao(conn);
mDao2.save(dto);
posted on 2007-05-02 13:24 afunms 閱讀(118) 評論(0) 編輯 收藏
We'd much rather change the world instead of going along with it.
Powered by: BlogJava Copyright © afunms