코딩해징징징징
72
2016-10-03 15:42:59 작성 2016-10-03 15:51:05 수정됨
5
2069

Auto Increment를 했더니 DB에 데이터가 저장이 안됩니다ㅠㅠ


게시글 번호(room_no)를 수동으로 넣어줬을 때는 DB에 모두 저장이 됐는데

auto increment를 하니 그 뒤로 NULL값만 들어갑니다ㅠㅠ이게 무슨 일일까요..!


public void insertArticle(RoomBoardDataBean article) 

            throws Exception {

        Connection conn = null;

        PreparedStatement pstmt = null;

ResultSet rs = null;


int number=0;

        String sql="";


        try {

            conn = getConnection();


            pstmt = conn.prepareStatement("select max(room_no) from room_info");

rs = pstmt.executeQuery();

if (rs.next())

     number=rs.getInt(1)+1;

  else

     number=1; 

  

            // 쿼리를 작성

            sql = "insert into room_info (room_no,matching_con_no,room_type,address_gu,address_dong,";

   sql+="room_extent,room_floor,room_building_floor,room_cost,mon_price,year_price,room_title,room_content,room_write_date,room_park_check,room_due_date,room_endornot,";

   sql+="agent_no,user_no,opt_refrige,opt_washingmachine,opt_tv,opt_air_con,opt_induction,opt_oven,";

   sql+="opt_bidet,opt_shoe_rack,opt_desk,opt_bed,opt_gas,opt_lock,opt_closet,img1,img2,img3,img4,img5) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

   

            pstmt = conn.prepareStatement(sql);

            pstmt.setInt(1, article.getRoom_no());

            pstmt.setInt(2, article.getMatching_con_no());

            pstmt.setString(3, article.getRoom_type());

            pstmt.setString(4, article.getAddress_gu());

...

pstmt.setString(37, article.getImg5());

} catch(Exception ex) { ex.printStackTrace(); } finally { if (rs != null) try { rs.close(); } catch(SQLException ex) {} if (pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if (conn != null) try { conn.close(); } catch(SQLException ex) {} } }

            pstmt.executeUpdate();

여기가 insert하는 DBBean입니다ㅠㅠ


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ page import = "room.board.RoomBoardDBBean" %>

<%@ page import = "room.board.RoomBoardDataBean" %>


<%@ page import = "java.sql.Timestamp" %>


<% request.setCharacterEncoding("utf-8");%>


<jsp:useBean id="article" class="room.board.RoomBoardDataBean">

  <jsp:setProperty name="article" property="*"/>

</jsp:useBean>

 

<%

  RoomBoardDBBean dbPro = RoomBoardDBBean.getInstance();

  dbPro.insertArticle(article); 


  response.sendRedirect("agentTemplate.jsp?CONTENT=layer.jsp");

%>


여기는 Pro부분입니다!!!


10월 03, 2016 3:36:43 오후 org.apache.catalina.core.StandardContext reload

정보: Reloading Context with name [/cban] has started

10월 03, 2016 3:36:43 오후 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc

경고: The web application [cban] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

10월 03, 2016 3:36:43 오후 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads

경고: The web application [cban] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:

 java.lang.Object.wait(Native Method)

 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)

 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:40)

10월 03, 2016 3:36:44 오후 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance

경고: Name = cban Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "5000" for "maxWait" property, which is being ignored.

10월 03, 2016 3:36:44 오후 org.apache.jasper.servlet.TldScanner scanJars

정보: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

10월 03, 2016 3:36:44 오후 org.apache.catalina.core.StandardContext reload

정보: Reloading Context with name [/cban] is completed

뭐가 문제인걸까요ㅠㅠ도와주세요!!!


0
0
  • 답변 5

  • 미치겠네
    42
    2016-10-03 16:21:40

    알려드리고 싶은데 모르겠네요..ㅜ

    0
  • 제타건담
    6k
    2016-10-03 19:36:41

    지금 쿼리로는 당연 오류가 나지 싶네요..room_no 가  자동증가 컬럼이면 insert  문에서 빠져야 합니다..

    근데 그렇게 안되어 있고..

    아마  자동증가 컬럼 설정때문에 기존 데이터를 지우신거 같은데..

    만약 데이터가 일절 없는 상태에서..


    select max(room_no) from room_info


    이 쿼리를 돌렸을때 머가 나올까요? 그 값에 1을 더할 수 있을까요?


    정리하면..자동증가 컬럼 설정을 해놓고 쿼리 방식은 이전것을 그대로 사용하고 있기 때문에 문제가 생기는겁니다..자동증가 컬럼을 사용하고 있다면 insert 문만 사용하세요..


    1
  • 코딩해징징징징
    72
    2016-10-03 20:11:24

    ㅠㅠ감사합니다 예제를 따라 저렇게 해봤습니다!!

    insert문에 room_no부분을 빼고 데이터를 넣었더니 여전히..!

    room_no는 계속 증가하지만 나머지 컬럼들엔 값이...8ㅅ8 안들어갑니다!!ㅠㅠ

    그래서 Pro부분에

    <%

      int room_no = Integer.parseInt(request.getParameter("room_no"));

      int matching_con_no = Integer.parseInt(request.getParameter("matching_con_no"));

      String room_type = request.getParameter("room_type");

      String address_gu = request.getParameter("address_gu");

      String address_dong = request.getParameter("address_dong");

      String room_extent = request.getParameter("room_extent");

      String room_floor = request.getParameter("roon_floor");

      String room_building_floor = request.getParameter("room_building_floor");

      String room_cost = request.getParameter("room_cost");

      String mon_price = request.getParameter("mon_price");

      String year_price = request.getParameter("year_price");

      String room_park_check = request.getParameter("room_park_check");

      String room_endornot = request.getParameter("room_endornot");

      int agent_no = Integer.parseInt(request.getParameter("agent_no"));

      int user_no = Integer.parseInt(request.getParameter("user_no"));

      String room_title = request.getParameter("room_title");

      String room_content = request.getParameter("room_content");

      int opt_refrige = Integer.parseInt(request.getParameter("opt_refrige"));

      int opt_washingmachine = Integer.parseInt(request.getParameter("opt_washingmachine"));

      int opt_tv = Integer.parseInt(request.getParameter("opt_tv"));

      int opt_air_con = Integer.parseInt(request.getParameter("opt_air_con"));

      int opt_induction = Integer.parseInt(request.getParameter("opt_induction"));

      int opt_oven = Integer.parseInt(request.getParameter("opt_oven"));

      int opt_bidet = Integer.parseInt(request.getParameter("opt_bidet"));

      int opt_shoe_rack = Integer.parseInt(request.getParameter("opt_shoe_rack"));

      int opt_desk = Integer.parseInt(request.getParameter("opt_desk"));

      int opt_bed = Integer.parseInt(request.getParameter("opt_bed"));

      int opt_gas = Integer.parseInt(request.getParameter("opt_gas"));

      int opt_lock = Integer.parseInt(request.getParameter("opt_lock"));

      int opt_closet = Integer.parseInt(request.getParameter("opt_closet"));

      String img1 = request.getParameter("img1");

      String img2 = request.getParameter("img2");

      String img3 = request.getParameter("img3");

      String img4 = request.getParameter("img4");

      String img5 = request.getParameter("img5");



      article.setRoom_no(room_no);

      article.setMatching_con_no(matching_con_no);

      article.setRoom_write_date(new Timestamp(System.currentTimeMillis()));

      article.setRoom_type(room_type);

      article.setAddress_gu(address_gu);

      article.setAddress_dong(address_dong);

      article.setRoom_extent(room_extent);

      article.setRoom_floor(room_floor);

      article.setRoom_building_floor(room_building_floor);

      article.setRoom_cost(room_cost);

      article.setMon_price(mon_price);

      article.setYear_price(year_price);

      article.setRoom_park_check(room_park_check);

      article.setRoom_due_date(new Timestamp(System.currentTimeMillis()));

      article.setRoom_endornot(room_endornot);

      article.setAgent_no(agent_no);

      article.setUser_no(user_no);

      article.setRoom_title(room_title);

      article.setRoom_content(room_content);

      article.setOpt_refrige(opt_refrige);

      article.setOpt_washingmachine(opt_washingmachine);

      article.setOpt_tv(opt_tv);

      article.setOpt_air_con(opt_air_con);

      article.setOpt_induction(opt_induction);

      article.setOpt_oven(opt_oven);

      article.setOpt_bidet(opt_bidet);

      article.setOpt_shoe_rack(opt_shoe_rack);

      article.setOpt_desk(opt_desk);

      article.setOpt_bed(opt_bed);

      article.setOpt_gas(opt_gas);

      article.setOpt_lock(opt_lock);

      article.setOpt_closet(opt_closet);

      article.setImg1(img1);

      article.setImg2(img2);

      article.setImg3(img3);

      article.setImg4(img4);

      article.setImg5(img5);

      

      RoomBoardDBBean dbPro1 = RoomBoardDBBean.getInstance();

      dbPro1.insertArticle(article); 

      

      response.sendRedirect("agentTemplate.jsp?CONTENT=layer.jsp");

    %>

    이렇게 추가했는데..여전합니다ㅠㅠ..!pro가 문제인걸까요 DBBean의 sql문이 문제인걸까요ㅠㅠ

    0
  • 제타건담
    6k
    2016-10-03 21:47:40

    그래도 null이 들어가진다면 생각할수 있는건 애초에 값이 넘어가지 않는거 뿐이 없어 보이는데요..

    article 변수에 셋팅하는 request에서 읽어오는 값들이 제대로 넘어오는지에 대한 확인을 해보시죠..

    1
  • 코딩해징징징징
    72
    2016-10-04 18:45:11

    감사합니다ㅠㅠ제가 form에서 보낼 때 multipart/formdata로 보내서 그랬던것 같습니다!!고치니까 보내져요!ㅎㅎㅎ

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