ArticleDao 의 getArticles에 MySQLUtil 적용 (1차)
//1차로 DB연결하기
public class App {
public void run() {
Scanner sc = Container.scanner;
ArticleController articleController = new ArticleController();
while (true) {
System.out.printf("명령어) ");
String cmd = sc.nextLine();
MysqlUtil.setDBInfo("127.0.0.1","sbsst", "sbs123414"
boolean needToExit = false;
if (cmd.startWith("article ")) {
articleController.doCommand(cmd);
} else if (cmd.equals("system exit")) {
System.out.println("* 시스템 종료 *");
needToExit = true;
}
MysqlUtil.closeConnection();
if ( needToExit ) {
break;
}
//2차
public class ArticleDao {
public List<Article> getArticles() {
List<Article> articles = new ArrayList<>();
SecSql sql = new SecSql();
sql.append("SELECT *");
sql.append("FROM article");
sql.append("ORDER BY id DESC");
List<Map<String, Object>> articleMapList = MysqlUtil.selectRows(sql);
for ( Map<String, Object> articleMap : articleMapList) {
articles.add(new Article(articleMap));
}
return articles;
}
}
ArticleDao 의 getArticles에 MySQLUtil 적용 (2차)
public Article getArticles(int id) {
SecSql sql = new SecSql();
sql.append("SELECT *");
sql.append("FROM article");
sql.append("WHERE id = ?", id);
Map<String, Object>> articleMap = MysqlUtil.selectRow(sql);
if ( articleMap.isEmpty() ) {
return null;
}
return new Article(articleMap);
}
*전체적인 일상은 노션을 통해 작성하고 있습니다.
'SQL' 카테고리의 다른 글
#075 ArticleDao 의 getArticles에 MySQLUtil 적용하기 (3차 - 로그인/로그아웃 & 내 정보) (0) | 2021.01.14 |
---|---|
#074 ArticleDao 의 getArticles에 MySQLUtil 적용하기 (2차 - Delete & Modify) (0) | 2021.01.14 |
#072 [MySQL 과제] Article Map List 응용문제 (0) | 2021.01.05 |
#071 Map과 List의 차이점 (0) | 2021.01.05 |
#070 map대신 article 쓰고 싶을 때 방법 (0) | 2021.01.05 |