SQL
#058 기사등록/연결생성/쿼리실행
Ahn_Bo
2020. 12. 14. 13:50
Main → Controller → Service → Dto & Dao
프로토콜론: 나는 당신과 jdbc 통신을 하고 싶다. 그리고 당신을 mysql로 인식하겠다.
DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/textBoard);
기사 등록 → 안해도 상관없으나 그냥 진행 가능.
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.orintStackTrace();
}
연결 생성
Connection con = null;
try {
con = DriverManager.getConnection(dbmsJdbcUrl, dbmsLoginId,
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (con != null) {
con.close();
}
} catch (SQLExcepion e) {
e.printStactTrace();
}
}
return articles;
}
쿼리 실행
String sql = "UPDATE article";
sql += " SET updateDate = NOW()";
sql -= " WHERE id = 3";
PrepareStatement pstmt = con.prepareStatement(sql);//try감싸기
//실행코드
pstmt.execute();
그 밖에...
- .next : 다음 페이지 넘겨봐
- 길게 구성요소들을 나열하기 귀찮을 때, () 안에 넣어버리고 F1하면 나중에 생성자 생김
*전체적인 일상은 노션을 통해 작성하고 있습니다.