資源簡介
已實現(xiàn)部分功能,其它自己琢磨,有數(shù)據(jù)庫,框架已搭好,其它很容易實現(xiàn)了

代碼片段和文件信息
package?org.news.dao;
import?java.sql.Connection;
import?java.sql.DriverManager;
import?java.sql.PreparedStatement;
import?java.sql.ResultSet;
import?java.sql.SQLException;
import?java.sql.Statement;
import?org.news.util.ConfigManager;
/**
?*?數(shù)據(jù)庫連接與關(guān)閉工具類。
?*?
?*?@author?北大青鳥
?*/
public?class?baseDao?{
????private?static?String?driver?=?ConfigManager.getProperty(“driver“);//?數(shù)據(jù)庫驅(qū)動字符串
????private?static?String?url?=?ConfigManager.getProperty(“url“);//?連接URL字符串
????private?static?String?user?=?ConfigManager.getProperty(“user“);?//?數(shù)據(jù)庫用戶名
????private?static?String?password?=?ConfigManager.getProperty(“password“);?//?用戶密碼
????protected?Connection?conn;
????static?{
????????try?{
????????????Class.forName(driver);
????????}?catch?(ClassNotFoundException?e)?{
????????????//?TODO?Auto-generated?catch?block
????????????e.printStackTrace();
????????}
????}
????/**
?????*?獲取數(shù)據(jù)庫連接對象。
?????*/
????public?Connection?getConnection()?{
????????//?獲取連接并捕獲異常
????????try?{
????????????if?(conn?==?null?||?conn.isClosed())
????????????????conn?=?DriverManager.getConnection(url?user?password);
????????}?catch?(SQLException?e)?{
????????????e.printStackTrace();
????????}
????????return?conn;//?返回連接對象
????}
????/**
?????*?關(guān)閉數(shù)據(jù)庫連接。
?????*?
?????*?@param?conn
?????*????????????數(shù)據(jù)庫連接
?????*?@param?stmt
?????*????????????Statement對象
?????*?@param?rs
?????*????????????結(jié)果集
?????*/
????public?void?closeAll(Connection?conn?Statement?stmt?ResultSet?rs)?{
????????//?若結(jié)果集對象不為空,則關(guān)閉
????????try?{
????????????if?(rs?!=?null?&&?!rs.isClosed())
????????????????rs.close();
????????}?catch?(Exception?e)?{
????????????e.printStackTrace();
????????}
????????//?若Statement對象不為空,則關(guān)閉
????????try?{
????????????if?(stmt?!=?null?&&?!stmt.isClosed())
????????????????stmt.close();
????????}?catch?(Exception?e)?{
????????????e.printStackTrace();
????????}
????????//?若數(shù)據(jù)庫連接對象不為空,則關(guān)閉
????????try?{
????????????if?(conn?!=?null?&&?!conn.isClosed())
????????????????conn.close();
????????}?catch?(Exception?e)?{
????????????e.printStackTrace();
????????}
????}
????/**
?????*?增、刪、改操作
?????*?
?????*?@param?sql
?????*????????????sql語句
?????*?@param?prams
?????*????????????參數(shù)數(shù)組
?????*?@return?執(zhí)行結(jié)果
?????*/
????protected?int?executeUpdate(String?sql?object...?params)?{
????????int?result?=?0;
????????conn?=?this.getConnection();
????????PreparedStatement?pstmt?=?null;
????????try?{
????????????pstmt?=?conn.prepareStatement(sql);
????????????for?(int?i?=?0;?i?????????????????pstmt.setobject(i?+?1?params[i]);
????????????}
????????????result?=?pstmt.executeUpdate();
????????}?catch?(SQLException?e)?{
????????????e.printStackTrace();
????????}?finally?{
????????????closeAll(null?pstmt?null);
????????}
????????return?result;
????}
????/**
?????*?查詢操作
?????*?
?????*?@param?sql
?????*????????????sql語句
?????*?@param?params
?????*????????????參數(shù)數(shù)組
?????*?@return?查詢結(jié)果集
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-06-05?20:54??新聞發(fā)布系統(tǒng)\
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\
?????文件?????????877??2018-06-03?08:24??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.classpath
?????目錄???????????0??2018-06-01?10:12??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.myeclipse\
?????文件?????????305??2018-06-03?08:16??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.myme
?????文件????????1757??2018-06-03?08:29??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.project
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.settings\
?????文件?????????500??2016-08-01?16:39??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.settings\.jsdtscope
?????文件?????????148??2018-06-04?14:42??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.settings\org.eclipse.core.resources.prefs
?????文件?????????364??2018-06-03?08:24??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.settings\org.eclipse.jdt.core.prefs
?????文件?????????625??2016-08-01?16:44??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.settings\org.eclipse.wst.common.component
?????文件?????????252??2016-08-01?16:39??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件??????????49??2016-08-01?16:39??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件???????????6??2016-08-01?16:39??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\resources\
?????文件?????????239??2018-06-04?14:42??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\resources\databa
?????文件?????????504??2016-08-01?16:44??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\resources\log4j.properties
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\
?????文件????????3830??2016-08-15?16:26??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\ba
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\impl\
?????文件????????3934??2018-06-03?14:04??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\impl\NewsDaoImpl.java
?????文件????????2701??2018-06-03?17:24??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\impl\TopicsDaoImpl.java
?????文件?????????948??2016-08-17?13:25??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\impl\UserDaoImpl.java
?????文件?????????436??2018-06-03?11:45??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\NewsDao.java
?????文件?????????452??2016-08-17?13:37??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\TopicsDao.java
?????文件?????????174??2016-08-01?16:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\dao\UserDao.java
?????目錄???????????0??2018-06-05?20:52??新聞發(fā)布系統(tǒng)\news_chapter04\news_chapter04\src\org\news\entity\
............此處省略110個文件信息
評論
共有 條評論