총총잉
78
2018-11-13 17:06:35 작성 2018-11-13 17:12:25 수정됨
6
4206

스프링 mvc게시판 insert ORA-01400 에러


안녕하세요!

게시판에서 글 등록 시, ORA-01400 에러가 발생하는데 해결 방법을 찾지 못해서 글 남깁니다ㅠㅠ 

매퍼와 동일한 쿼리로 sqldeveloper에서 데이터 입력 시에는 입력이 됩니다.. 

근데 화면에서 정보입력하고 넘길 때는 에러가 뜨네요 

값 찍어 봤을 때 [fbNum=0, fbTitle=ddd, fbContent=dddd, fbRegdate=null, fbViewcnt=0, fbWriter=null, fbCnt=0, fbShow=null, fbFiles=null]

이렇게 Writer가 null로 찍히고 값이 안들어가네요

에러 정보와 jsp, controller, dao, serviceImpl, mapper 코드 첨부합니다 

고수님들의 답변 부탁드립니당 .. 


console

11월 13, 2018 1:49:18 오후 org.apache.catalina.core.StandardWrapperValve invoke
심각: Servlet.service() for servlet [appServlet] in context with path [/ict] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: NULL을 ("SCOTT"."FREEBOARD"."FB_WRITER") 안에 삽입할 수 없습니다

### The error may involve freeboard.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO FREEBOARD (FB_NUM,FB_TITLE,FB_CONTENT,FB_WRITER) VALUES   ( (SELECT NVL(MAX(FB_NUM)+1,1) FROM FREEBOARD),   ?, ?, ? )
### Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: NULL을 ("SCOTT"."FREEBOARD"."FB_WRITER") 안에 삽입할 수 없습니다

; SQL []; ORA-01400: NULL을 ("SCOTT"."FREEBOARD"."FB_WRITER") 안에 삽입할 수 없습니다
; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-01400: NULL을 ("SCOTT"."FREEBOARD"."FB_WRITER") 안에 삽입할 수 없습니다
] with root cause
java.sql.SQLIntegrityConstraintViolationException: ORA-01400: NULL을 ("SCOTT"."FREEBOARD"."FB_WRITER") 안에 삽입할 수 없습니다

	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
	at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
	at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)
	at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1008)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)
	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
	at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3550)
	at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374)
	at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
	at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
	at net.sf.log4jdbc.PreparedStatementSpy.execute(PreparedStatementSpy.java:418)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
	at com.sun.proxy.$Proxy7.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
	at com.newdeal.ict.Dao.FreeBoardDao.create(FreeBoardDao.java:43)
	at com.newdeal.ict.Service.Impl.FreeBoardServiceImpl.create(FreeBoardServiceImpl.java:34)
	at com.newdeal.ict.Controller.FreeBoardController.insert(FreeBoardController.java:80)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:870)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)


jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ include file="../include/header.jsp" %>
<script src="${path}/include/js/common.js"></script>
<script>
$(function(){
	
	//드래그 기본효과 막음
	$(".fileDrop").on("dragenter dragover", function(e){
		e.preventDefault();
	});
	$(".fileDrop").on("drop",function(e){
		e.preventDefault();
		//드롭한 파일을 폼데이터에 추가함
		var fbFiles = e.originalEvent.dataTransfer.fbFiles;
		var file=fbFiles[0];
		var formData=new FormData();
		//폼데이터에 추가
		formData.append("file", file);
		//processData: false -header가 아닌 body로 전송
		$.ajax({
			url: "${path}/upload/uploadAjax",
			data: formData,
			dataType: "text",
			processData: false,
			contentType: false,
			type: "post",
			success: function(data){//콜백함수
				var fileInfo=getFileInfo(data);//첨부파일정보
				var html="<a href='"+fileInfo.getLink+"'>"+
				fileInfo.fileName+"</a><br>";//첨부파일링크
				html+="<input type='hidden' class='file' value='"
				+fileInfo.fullName+"'>"; //hidden태그 추가
				$("#uploadedList").append(html);//div에 추가
			}
		});
	});
	
		
	$("#btnSave").click(function(){
		//태그.each(function(){})모든 태그 반복
		var str="";
		$("#uploadedList .file").each(function(i){
			str+="<input type='hidden' name='fbFiles["+i+"]' value='"
			+$(this).val()+"'>";
		});
		//폼에 hidden 태그들을 추가
		$("#form").append(str);
		document.form.submit();
	});
});
</script>
<style>
.fileDrop {
	width: 300px;
	height: 80px;
	border: 1px solid #ededed;
}
</style>
</head>
<body>

<%@ include file="../include/menu.jsp" %>
<h2>자유게시판</h2>
<form id="form" name="form" method="post"
action="${path}/freeboard/insert.do">
	
	<%-- <input type="hidden" name="fbWriter" value="${member.memNickName}"/> --%>
	
	<div>
		제목 <input name="fbTitle" id="fbTitle" size="80"/>
	</div>
	<div>
		작성자 : <input type="hidden" id="fbWriter" value="${member.memNickName}" /> ${member.memNickName}
	</div>
	<div>
		첨부 파일<br>
		
		<!-- 0717추가 -->
		<div>
			<input type="file" name="file" id="btnUpload">
		</div>
	
		<!-- 첨부파일을 드래그할 영역 -->
		<div class="fileDrop">
			<!-- 첨부파일 목록이 표시되는 영역 -->
			<div id="uploadedList"></div>
		</div>
		<!-- 첨부파일 목록이 표시되는 영역
		<div id="uploadedList"></div> -->
	</div>
	<div style="width:800px;">
		내용 <textarea id="fbContent" name="fbContent" rows="3" cols="80"></textarea>
		<!-- <script>
		CKEDITOR.replace("fbContent",{
			filebrowserUploadUrl : "${path}/imageUpload.do"
		});
		</script> -->
	</div>
	<div style="width:700px; text-align:center;">
		<button type="button" id="btnSave">등록</button>
	</div>
</form>
</body>
</html>


controller

@RequestMapping("insert.do")
	public String insert(@ModelAttribute FreeBoardVo vo,HttpSession session) throws Exception{
		vo.setFbWriter((String)session.getAttribute("id"));
		
		System.out.println("=====================>"+vo.toString());
		service.create(vo);
		return "redirect:/freeboard/list.do";
	}


dao

public void create(FreeBoardVo vo) throws Exception {
		sqlSession.insert("freeboard.insert", vo);

	}



serviceImpl

@Transactional
	@Override
	public void create(FreeBoardVo vo) throws Exception {
		dao.create(vo);
	}


mapper

<!-- 게시물등록 -->
	<insert id="insert" parameterType="freeboard" >
		INSERT INTO FREEBOARD (FB_NUM,FB_TITLE,FB_CONTENT,FB_WRITER) VALUES
		( (SELECT NVL(MAX(FB_NUM)+1,1) FROM FREEBOARD),
		#{fbTitle,jdbcType=VARCHAR}, #{fbContent,jdbcType=CLOB}, #{fbWriter,jdbcType=VARCHAR} )
	</insert>
	


0
  • 답변 6

  • ghkdwls30
    2k
    2018-11-13 17:11:12

    아니 오류 보면 모르세요? 그래가지고 어떻게 개발자하실수 있겠음??

    아래 필드에 널을 넣을 수없다잖아요

    화면 OR 서버단에서 NULL을 넘기는 것을 제한하던가

    데이터베이스에서 NULL 들어가는거 허용하던가 둘중하나하세요

    FB_WRITER
    -3
  • 총총잉
    78
    2018-11-13 17:14:53

    ghkdwls30 모르니까 질문 글 올린거고 아직 개발자 아닙니다 .. 

  • 도레미
    272
    2018-11-13 17:20:40 작성 2018-11-13 17:21:07 수정됨
    <input type="hidden" name="fbWriter" id="fbWriter" value="${member.memNickName}" /> 수정해보세요(name추가)
  • 총총잉
    78
    2018-11-13 17:24:06

    도레미 수정했는데 똑같은 결과입니당 ㅜ_ㅜ.. 아무튼 감사합니당 ㅎㅎ!! 

  • 도레미
    272
    2018-11-13 17:27:03 작성 2018-11-13 18:04:36 수정됨

    vo.setFbWriter((String)session.getAttribute("id")); 에서 (String)session.getAttribute("id") 값은 있나요?
    값이 null이라면 화면에서 name 주시고 컨트롤러에서 vo.set 하는이부분 빼고 다시 해보세용
  • 총총잉
    78
    2018-11-14 09:54:40

    도레미 덕분에 해결했습니다 감사합니다 좋은하루되세요 ㅎㅎ 

  • 로그인을 하시면 답변 을 등록할 수 있습니다.