2019.07.23
// CRUD
대부분의 컴퓨터 소프트웨어가 가지는 기본적인 데이터 처리기능인
Create(생성), Read(읽기), Update(갱신), Delete(삭제) 를 묶어서 일컫는 말
단어 추가(생성, Create)
1
2
3
4
5
6
7
8
9
|
// DicDTO.java
package service;
public class DicDTO {
public int idx;
public String eng;
public String kor;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// DicDAO.java
package service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class DicDAO {
Connection conn = null;
PreparedStatement pstmt = null;
ArrayList<DicDTO> ald = null;
ResultSet rs = null;
// dic 단어 추가 메서드
public void insert(DicDTO dicDTO) throws ClassNotFoundException, SQLException {
DriverDB db = new DriverDB();
conn = db.driverDbcon();
pstmt = conn.prepareStatement("INSERT INTO dic (eng, kor) VALUES (?, ?)");
pstmt.setString(1, dicDTO.eng);
pstmt.setString(2, dicDTO.kor);
int result = pstmt.executeUpdate();
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<!-- jQuery library -->
<!-- Popper JS -->
<!-- Latest compiled JavaScript -->
</head>
<body>
<div class = "container">
<hr>
<h3> Dictionary </h3>
<div class = "text-right">
<hr>
</div>
<table class = "table table-striped">
<tr>
<th> eng </th>
<th> kor </th>
</tr>
<tr>
<td><input type = "text" name = "eng" class="form-control"></td>
<td><input type = "text" name = "kor" class="form-control"></td>
</tr>
</table>
<div class = "text-right">
<button type = "submit" class = "btn btn-outline-secondary"> 확인 </button>
</div>
</form>
</div>
</body>
</html>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%
request.setCharacterEncoding("euc-kr"); // 한글이 깨지지 않도록
String eng = request.getParameter("eng");
String kor = request.getParameter("kor");
// System.out.println(eng + " <-- eng dicInsertAction.jsp");
// System.out.println(kor + " <-- kor dicInsertAction.jsp");
DicDTO dicDTO = new DicDTO();
dicDTO.eng = eng;
dicDTO.kor = kor;
DicDAO dicDAO = new DicDAO();
response.sendRedirect(request.getContextPath() + "/dicList.jsp");
%>
|
'교육 > Java' 카테고리의 다른 글
#51 Java CRUD기능의 간단한 사전 만들기 Delete (0) | 2019.08.01 |
---|---|
#50 Java CRUD기능의 간단한 사전 만들기 Update (0) | 2019.08.01 |
#48 Java CRUD기능의 간단한 사전 만들기 Read (0) | 2019.08.01 |
#47 Java Servlet 기본 개념 (0) | 2019.08.01 |
#46 Java 오버로딩, 오버라이딩 (0) | 2019.07.31 |