티스토리 뷰
[Spring_Error]java.sql.SQLIntegrityConstraintViolationException: Column 'content' cannot be null
onlyun 2022. 3. 19. 04:29스프링으로 웹 게시판 만들다가 아래와 같은 오류를 맞딱드렸음.
org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'content' cannot be null
### The error may exist in com/wsy/wsyweb/mapper/BoardMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: insert into tbl_board(title, content, writer) values(?, ?, ?)
### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'content' cannot be null
; Column 'content' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'content' cannot be null
컬럼 content는 null이 되면 안 된다는 뜻.
MySQL에서 생성한 테이블의 content 열이 NN(Not Null) 설정되어 있기 때문에 데이터를 받아와야하는데
데이터를 받아오지 못하는 것.
<!-- 글 등록 -->
<insert id="insert">
insert into tbl_board(title, content, writer)
values(#{title}, #{content}, #{writer})
<!-- bno 자동 증가, regdate/updatedate는 자동입력 -->
</insert>
내 경우엔,
register.jsp - 입력 폼을 생성해 사용자가 데이터를 입력하게끔하는 곳에서
<input> 태그에 name 설정을 안 해줬기 때문.
<table class="tbl-content">
<tr> <!--★-->
<th colspan="3"><input type="text" class="title-txt" name="title" placeholder="제목을 입력하세요."></th>
</tr>
<tr>
<td class="tbl-field-form">작성자</td>
<td class="tbl-field-form-writer">
<input type="text" id="writer" name="writer"><!--★-->
</td>
<td class="tbl-content-btn"></td>
</tr>
<tr>
<td class="tbl-content-content" colspan="3">
<textarea name="content" rows="7" cols="150" placeholder="내용을 입력하세요."></textarea>
</td> <!--★-->
</tr>
<tr>
<td colspan="3">
<button type="submit" class="board-btn">등록</button> <!-- 버튼누를 경우, controller -->
</td>
</tr>
</table>
name 설정할 때, 쿼리문의 이름과 같게 해야 함. 아니면 못 가져옴.
- Total
- Today
- Yesterday
- css
- A%B
- ScriptTag
- 입력양식
- selcetor
- html atrribute
- scanner
- typeof
- html a tag
- JavaScript
- html layout
- border-spacing
- text formatting
- improt
- CascadingStyleSheet
- 외부구성요소
- 스크립태그
- caption-side
- html base tag
- empty-cell
- BAEKJOON
- 미디어 태그
- 변수
- 기본선택자
- Java
- input type 종류
- html pre
- initialized
- html
- html input type
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |