java

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

dev_summer 2020. 11. 9. 15:35

 

 

์‹ค์งˆ์ ์œผ๋กœ ์ฟผ๋ฆฌ๋ฌธ์„ ๋‚ ๋ฆฌ๋Š” 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 index out of range (5 > number of parameters, which is 3).

->(๋ฒˆ์—ญ)java.sql.SQLException : ๋งค๊ฐœ ๋ณ€์ˆ˜ ์ƒ‰์ธ์ด ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค (5> ๋งค๊ฐœ ๋ณ€์ˆ˜ ์ˆ˜, 3).

: ์ธ๋ฑ์Šค๋Š” 3๊นŒ์ง€ ์žˆ๋Š”๋ฐ ๋„ฃ์€ ์ธ๋ฑ์Šค๊ฐ’์€ 5๋ผ์„œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ

 

 

3. findById()ํ•จ์ˆ˜์—์„œ getInt("id")์— getInt("hello")๋กœ ๋„ฃ์–ด๋ณด๊ณ  ์‹คํ–‰ํ•ด๋ณด๊ธฐ

->java.sql.SQLException: Column 'hello' not found.

-> (๋ฒˆ์—ญ)java.sql.SQLException : 'hello'์—ด์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

: getint("์—ด์ด๋ฆ„)" ์ปฌ๋Ÿผ์ด๋ฆ„์ด ๋“ค์–ด๊ฐ€์•ผํ•จ. ์˜คํƒ€๊ฐ€ ๋‚ฌ์„๋•Œ ๋ฐœ์ƒํ• ์ˆ˜ ์žˆ๋Š” ์˜ค๋ฅ˜

 

 

 

4. findbyId()ํ•จ์ˆ˜์—์„œ ์—†๋Š” ์ปฌ๋Ÿผ๋ช…์„ SQL๋ณ€์ˆ˜์— ๋„ฃ๊ณ  ์‹คํ–‰ํ•ด๋ณด๊ธฐ

->java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where = 2' at line 1

->(๋ฒˆ์—ญ) java.sql.SQLSyntaxErrorException : SQL ๊ตฌ๋ฌธ์— ์˜ค๋ฅ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ผ์ธ 1์˜ 'where = 2'๊ทผ์ฒ˜์—์„œ ์‚ฌ์šฉํ•  ์˜ฌ๋ฐ”๋ฅธ ๊ตฌ๋ฌธ์€ MySQL ์„œ๋ฒ„ ๋ฒ„์ „์— ํ•ด๋‹นํ•˜๋Š” ๋งค๋‰ด์–ผ์„ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค.