๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ 101

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(7) ์˜ค๋ฅ˜๋ฌธ์ •๋ฆฌ:-)

์‹ค์งˆ์ ์œผ๋กœ ์ฟผ๋ฆฌ๋ฌธ์„ ๋‚ ๋ฆฌ๋Š” UserDaoTestํŒŒ์ผ์—์„œ ๋‚˜ํƒ€๋‚˜๋Š” ์˜ค๋ฅ˜๋“ค ํ™•์ธํ•˜๊ธฐ 1. save()ํ•จ์ˆ˜์—์„œ ? ์ œ๊ฑฐ ํ›„ ์‹คํ–‰ํ•ด๋ณด๊ธฐ -> java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2). ->(๋ฒˆ์—ญ) java.sql.SQLException : ๋งค๊ฐœ ๋ณ€์ˆ˜ ์ƒ‰์ธ์ด ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค (3> ๋งค๊ฐœ ๋ณ€์ˆ˜ ์ˆ˜, 2). : ?์˜ ๊ฐฏ์ˆ˜๋งŒํผpstmt.setString(1, "love"); setํ˜•์‹(์ธ๋ฑ์Šค,"๊ฐ’") ํ•ด์ฃผ์–ด์•ผํ•˜๋Š”๋ฐ ๋ฒ”์œ„๊ฐ€ ์•ˆ๋งž์Œ. 2. save()ํ•จ์ˆ˜์—์„œ setString(์—†๋Š”์ธ๋ฑ์Šค, ๊ฐ’) ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ ๋งˆ์Œ๋Œ€๋กœ ๋„ฃ์–ด๋ณด๊ณ  ์‹คํ–‰ํ•ด๋ณด๊ธฐ ->java.sql.SQLException: Parameter i..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ(6) PrepareStatement๋ฅผ ์ด์šฉํ•œ CRUD ํ…Œ์ŠคํŠธ

1.CRUD (1) C -> Create -> insert -> HTTP(POST) (2) R -> Read -> select -> HTTP(GET) (3) U -> Update - > update -> HTTP(PUT) (4) D -> Delete -> delete -> HTTP(DELETE) 2.User CRUD ํ…Œ์ŠคํŠธ (1) model/User.java package com.cos.board.model; import java.sql.Timestamp; // model, vo(value object), bean(์ฝฉ) public class User { private int id; private String username; private String password; private String ema..

java 2020.11.09

MySQL ์˜ค๋ฅ˜๋ฉ”์‹œ์ง€

Error: 1000 SQLSTATE: HY000 (ER_HASHCHK) Message: hashchk Error: 1001 SQLSTATE: HY000 (ER_NISAMCHK) Message: isamchk Error: 1002 SQLSTATE: HY000 (ER_NO) Message: NO Error: 1003 SQLSTATE: HY000 (ER_YES) Message: YES Error: 1004 SQLSTATE: HY000 (ER_CANT_CREATE_FILE) Message: '%s' ํŒŒ์ผ์„ ๋งŒ๋“ค ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค (errno: %d) Error: 1005 SQLSTATE: HY000 (ER_CANT_CREATE_TABLE) Message: '%s' ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.(errno: %d) E..

db 2020.11.09

JSP - ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ(5) DB Connection Pool(CP)

p.443 DB Connection Pool(CP) : datasource 1. ํ†ฐ์บฃ ์‚ฌ์ดํŠธ๋กœ ์ด๋™ (http://tomcat.apache.org/) 2. ๋ฒ„์ „์— ๋งž๊ฒŒ ํด๋ฆญ ํ†ฐ์บฃ ํŽ˜์ด์ง€ ์™ผ์ชฝ ๋ฐ” 3. JDBC Datasouce๋กœ ์ด๋™ 4. MySQL DBCP ์˜ˆ์ œ ๋ณด๊ธฐ 5. JDBC MySQL Connector ๋‹ค์šด๋กœ๋“œ https://www.mysql.com/products/connector/๋กœ ์ด๋™ 6. MySQL๋ฒ„์ „์œผ๋กœ ๋‹ค์šด๋กœ๋“œ, ์••์ถ• ํ’€๊ณ  jarํŒŒ์ผ lib์— ๋„ฃ๊ธฐ, ๋”ฐ๋กœ ๋นŒ๋“œํŒจ์Šค ์•ˆํ•ด๋„๋จ 7. ์†Œ์Šค์ฝ”๋“œ ์ž‘์„ฑ http://tomcat.apache.org/tomcat-8.5-doc/jndi-datasource-examples-howto.html#MySQL_DBCP_2_Example http://tomc..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(2) - MySQL ํ•œ๊ธ€ ์…‹ํŒ…ํ•˜๊ธฐ, ์œ ์ € ์ƒ์„ฑ

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์„œ๋ฒ„๋ฅผ urf-8๋กœ ๋ณ€๊ฒฝํ•ด์•ผํ•œ๋‹ค. ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์œˆ๋„์šฐ์™€ ๋ฆฌ๋ˆ…์Šค๊ฐ€ ๋‹ค๋ฅด๋‹ค. ๊ฒฝ๋กœ : C:\ProgramData\MySQL\MySQL Server 5.7 1. ์œˆ๋„์šฐ (1) my.ini ํŒŒ์ผ ์ฐพ๊ธฐ ๊ฒฝ๋กœ : C:\ProgramData\MySQL\MySQL Server 5.7 (2) ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ my.iniํŒŒ์ผ ์—ด์–ด์„œ ์ˆ˜์ •ํ•˜๊ธฐ ๋ฉ”๋ชจ์žฅ ๋งˆ์šฐ์Šค์šฐํด๋ฆญํ•˜์—ฌ ๊ด€๋ฆฌ์ž๊ถŒํ•œ์œผ๋กœ ์—ด๊ธฐ, ๋ชจ๋“ ํŒŒ์ผ๋กœ my.ini์—ด๊ธฐ [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] collation-server = utf8_unicode_ci init-connect='SET NAMES utf8' init_connect='SET col..

java 2020.11.09

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(1) - ํŒฉํ† ๋ฆฌ ํŒจํ„ด ์˜ˆ์ œ

์ฐธ๊ณ ์ž๋ฃŒ : https://readystory.tistory.com/117 [์ƒ์„ฑ ํŒจํ„ด] ํŒฉํ† ๋ฆฌ ํŒจํ„ด(Factory Pattern) ์ดํ•ด ๋ฐ ์˜ˆ์ œ ์ด๋ฒˆ์— ์‚ดํŽด๋ณผ ๋””์ž์ธ ํŒจํ„ด์€ ๊ฐ€์žฅ ์œ ๋ช…ํ•œ ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํ•˜๋‚˜์ธ ํŒฉํ† ๋ฆฌ ํŒจํ„ด(Factory Pattern)์ž…๋‹ˆ๋‹ค. ์ด ํŒฉํ† ๋ฆฌ ํŒจํ„ด์€ ์กฐ๊ธˆ ๋” ๊ตฌ์ฒด์ ์ธ ์šฉ์–ด์ธ ํŒฉํ† ๋ฆฌ ๋ฉ”์†Œ๋“œ ํŒจํ„ด(Factory Method Pattern)์œผ๋กœ๋„ ๋„๋ฆฌ readystory.tistory.com [์ƒ์„ฑ ํŒจํ„ด] ํŒฉํ† ๋ฆฌ ํŒจํ„ด(Factory Pattern) ์ดํ•ด ๋ฐ ์˜ˆ์ œ ์ด๋ฒˆ์— ์‚ดํŽด๋ณผ ๋””์ž์ธ ํŒจํ„ด์€ ๊ฐ€์žฅ ์œ ๋ช…ํ•œ ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํ•˜๋‚˜์ธ ํŒฉํ† ๋ฆฌ ํŒจํ„ด(Factory Pattern)์ž…๋‹ˆ๋‹ค. ์ด ํŒฉํ† ๋ฆฌ ํŒจํ„ด์€ ์กฐ๊ธˆ ๋” ๊ตฌ์ฒด์ ์ธ ์šฉ์–ด์ธ ํŒฉํ† ๋ฆฌ ๋ฉ”์†Œ๋“œ ํŒจํ„ด(Factory Method Pattern)์œผ๋กœ..

java 2020.11.09

MVCํŒจํ„ด

* ๊ธฐ์กด์˜ ๋ฐฉ์‹ ๋‹จ์  - MVC๋ง๊ณ ๋„ MVP, MCCM, ObserverํŒจํ„ด ๋“ฑ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. - MVC์ด ๊ธฐ๋ณธ์ด๊ธฐ๋•Œ๋ฌธ์— ๊ฐ€์žฅ ๋งŽ์ด ๋ฐฐ์›€. ๋‹จ์  ๋ณด์™„ ๋ฐฉ๋ฒ• - JSP๋ฐฉ์‹ JSP์—์„œ JSP๋กœ ์ด๋™ํ•œ๋‹ค. URL๋ฐฉ์‹์œผ๋กœ ํŒŒ์ผ๋ช…์„์ฐพ์Œ. ์„œ๋ธ”๋ฆฟ(์–ด๋…ธํ…Œ์ด์…˜) ์‚ฌ์šฉ - ๋น„์ง€๋‹ˆ์Šค๋กœ์ง + ๋ทฐ๋กœ์ง -> ๊ด€์‹ฌ์‚ฌ๊ฐ€ ๋ถ„๋ฆฌ๊ฐ€ ์•ˆ๋˜์–ด ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. MVCํŒจํ„ด ์‚ฌ์šฉ - ํŒจํ„ด์ด ์—†๋‹ค. ๊ฐœ๋ฐœ์ž ๊ฐ๊ฐ ์ง€์ผœ์•ผํ•  ๊ทœ์น™์ด ์—†๋‹ค -> ์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉ ํŒฉํ† ๋ฆฌ ์‚ฌ์šฉ ๋ณด์™„ ๋ฐฉ๋ฒ• - JSP๋ฐฉ์‹ JSP์—์„œ JSP๋กœ ์ด๋™ํ•œ๋‹ค. URL๋ฐฉ์‹์œผ๋กœ ํŒŒ์ผ๋ช…์„์ฐพ์Œ. ์„œ๋ธ”๋ฆฟ(์–ด๋…ธํ…Œ์ด์…˜) ์‚ฌ์šฉ - ๋น„์ง€๋‹ˆ์Šค๋กœ์ง + ๋ทฐ๋กœ์ง -> ๊ด€์‹ฌ์‚ฌ๊ฐ€ ๋ถ„๋ฆฌ๊ฐ€ ์•ˆ๋˜์–ด ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. MVCํŒจํ„ด ์‚ฌ์šฉ - ํŒจํ„ด์ด ์—†๋‹ค. ๊ฐœ๋ฐœ์ž ๊ฐ๊ฐ ์ง€์ผœ์•ผํ•  ๊ทœ์น™์ด ์—†๋‹ค -> ์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉ ํŒฉํ† ..

java 2020.11.09

JAVA - Exception ์ข…๋ฅ˜

ClassNotFoundException ํด๋ž˜์Šค๋ฅผ ์ฐพ์ง€ ๋ชปํ•จ CloneNotSupportedException Cloneable ์ธํ„ฐํŽ˜์ด์Šค ๋ฏธ๊ตฌํ˜„ IllegalAccessException ํด๋ž˜์Šค ์ ‘๊ทผ์„ ๋ชปํ•จ InstantiationException ์ถ”์ƒ ํด๋ž˜์Šค ๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ธ์Šคํ„ด์Šคํ™” ํ•˜๊ณ ์ž ํ• ๋•Œ InterruptedException ์“ฐ๋ ˆ๋“œ๊ฐ€ ์ค‘๋‹จ ๋˜์—ˆ์„๋•Œ NoSuchFieldException ์ง€์ •๋œ ํ•„๋“œ๊ฐ€ ์—†์„๋•Œ NoSuchMethodException ์ง€์ •๋œ ๋ฉ”์†Œ๋“œ๊ฐ€ ์—†์„๋•Œ [IOException] CharConversionException ๋ฌธ์ž ๋ณ€ํ™˜์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„๋•Œ [IOException] EOFException ํŒŒ์ผ์˜ ๋์— ๋„๋‹ฌํ–ˆ์„๋•Œ [IOException] FileNotFoundExcept..

java 2020.11.09

JSP - ๊ฐœ๋…์ •๋ฆฌ

* ์„ธ์…˜ - ์„ธ์…˜์€ ์‚ฌ์šฉ์žํŽ˜์ด์ง€์—์„œ ์•ˆ๋ณด์ด๊ณ  ์„œ๋ฒ„๊ฐ€ ๋“ค๊ณ ์žˆ๋Š” ๋ฐ์ดํ„ฐ, ๋ฆฌํ€˜์ŠคํŠธ ์•ˆ์— ์ €์žฅ๋œ๋‹ค. - ํ†ฐ์บฃ ๋‚ด์— ์„ธ์…˜์ปจํ…์ŠคํŠธ์— key, value,๋“ค์–ด์˜ค๋Š” ์Šค๋ ˆ๋“œ(์‚ฌ์šฉ์ž)๋งˆ๋‹ค ๊ด€๋ฆฌ ๋œ๋‹ค. * JSP์—์„œ๋Š” out์ด ๋‚ด์žฅ๊ฐ์ฒด์ด์ง€๋งŒ, java์—์„œ๋Š” out์ด ๋‚ด์žฅ๊ฐ์ฒด๊ฐ€ ์•„๋‹ˆ๊ธฐ๋•Œ๋ฌธ์— JAVA์—์„œ ์“ธ๋• printWriter๋กœ ์‚ฌ์šฉํ•˜์—ฌ stream์— ์ ‘๊ทผํ•œ๋‹ค. PrintWriter out = response.getWriter(); out.print(""); ํ˜•์‹์œผ๋กœ ๋„˜๊ฒจ์ค˜์•ผํ•œ๋‹ค * request์˜ ์žฌํ™œ์šฉ - request์˜ ์žฌํ™œ์šฉ์€ ์„œ๋ฒ„์—์„œ๋งŒ ํ• ์ˆ˜์žˆ๋‹ค. ์‚ฌ์šฉ์ž๋Š” ์žฌ์‚ฌ์šฉ ํ• ์ˆ˜ ์—†๋‹ค. - ํ†ฐ์บฃ์€ ํ•ญ์ƒ ์ƒˆ๋กœ์šด request, response๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. requestDispatcher๋ฅผ ์ด์šฉํ•˜๋ฉด ์ƒˆ๋กœ์ƒ์„ฑ๋œ request, r..

java 2020.11.09

jsp - include

* include ์ง€์‹œ์–ด p.157 jspํŒŒ์ผ ๋˜๋Š” htmlํŒŒ์ผ์„ ํ•ด๋‹น jspํŽ˜์ด์ง€์— ์‚ฝ์ž…ํ• ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ์ง€์‹œ์–ด์ด๋‹ค. ํ™”๋ฉด์— ๊ณตํ†ต์ ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” ๋ฉ”๋‰ด๋ฐ” ์ฝ”๋“œ๋ฅผ include์ง€์‹œ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ€๋…์„ฑ์ด ์ข‹๊ณ  ๊ณตํ†ต๋˜๋Š” ๋ถ€๋ถ„์„ ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. ์ด๋•Œ ํฌํ•จ๋˜๋Š” ํŒŒ์ผ๋“ค์€ ์‹ค์ œ ์ปดํŒŒ์ผ ๊ณผ์ •์„ ๊ฑฐ์ณ์„œ ๊ทธ ๊ฒฐ๊ณผ๊ฐ€ ํ•ด๋‹น jspํŽ˜์ด์ง€์— ํฌํ•จ๋˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ jsp์ฝ”๋“œ๊ฐ€ ํ•ด๋‹นjspํŽ˜์ด์ง€์— ๋ณต์‚ฌ๋˜์–ด ๋”ํ•ด์ง€๋ฏ€๋กœ ์„œ๋ธ”๋ฆฟ ์ปดํŒŒ์ผ ์‹œ ํ•œ๋ฒˆ์— ์ปดํŒŒ์ผ ๋œ๋‹ค. ๋ณ€์ˆ˜๋กœ์„œ๋„ ํ™œ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ includeํŒŒ์ผ์€ ํ•ฉ์ณ์„œ ์ปดํŒŒ์ผ ๋˜๋ฏ€๋กœ /body, /html์ด ์—†์Œ์— ์œ ์˜ํ•ด์•ผํ•œ๋‹ค. include์—์„œ ๊ฒฝ๋กœ ์ฐพ๋Š” ๊ธฐ๋ฒ•๊ณผ html๊ฒฝ๋กœ์ฐพ๋Š” ๊ธฐ๋ฒ•์ด ๋‹ค๋ฅด๋‹ค. *๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์ฐธ๊ณ  ์ฝ”๋“œ https://www.w3schools.com/bootst..

java 2020.10.30