Background Image

FORUM

조회 수 8917 추천 수 0 댓글 2
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부



package test.test.test;


import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.Locale;


import javax.sql.DataSource;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.jdbc.core.PreparedStatementCreator;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import org.springframework.jdbc.support.GeneratedKeyHolder;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;


/**

 * Handles requests for the application home page.

 */

@Controller

public class HomeController extends JdbcDaoSupport {

@Autowired

public void setDataSourceForAutoWire(DataSource ds){

super.setDataSource(ds);

}

/**

* Simply selects the home view to render by returning its name.

*/

@RequestMapping(value = "/", method = RequestMethod.GET)

public String home(Locale locale, Model model) {

GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

System.out.println("DB Source obejct check : " + getJdbcTemplate().getDataSource().toString()); 

try{

getJdbcTemplate().update("DROP TABLE test_tbl;");

}catch(Exception e){

//없을수도 있음

}


getJdbcTemplate().update(

"CREATE TABLE test_tbl( " +

"tt_idx INTEGER AUTO_INCREMENT PRIMARY KEY, " +

"tt_str character varying(15) NOT NULL, " +

"tt_dt datetime " +

")"

);

getJdbcTemplate().update(

new PreparedStatementCreator() {

public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

PreparedStatement ps = con.prepareStatement("INSERT INTO test_tbl(" +

"tt_str, " +

"tt_dt" +

") VALUES(" +

"?, " +

"sysdate" +

")",

Statement.RETURN_GENERATED_KEYS

);

ps.setString(1, "test");

return ps;

}

},

generatedKeyHolder

);

System.out.println(generatedKeyHolder.getKey() == null ? "getKey is NULL" : "OK");

System.out.println(generatedKeyHolder.getKeyList().size() == 0 ? "getKeyList is empty" : "OK");

System.out.println(generatedKeyHolder.getKeys() == null ? "getKeys is NULL" : "OK");

return "home";

}

}





이렇게 해본 결과 키가 나오지 않습니다.


DB Source obejct check : org.apache.commons.dbcp.BasicDataSource@3acc7
getKey is NULL
getKeyList is empty
getKeys is NULL




스프링 JdbcTemplate 을 사용해서 큐브리드 사용이 다른건 다 되는거 같은데,

키 가져오는것은 안되는거 같네요.

혹시 방법이 없을까요?


  • ?
    이용미 2012.08.27 18:03

    안녕하세요. 질문 감사드립니다.

     

    우선, 바인드를 사용한 쿼리를 Static으로 변경하여 Test가 가능하신가요?

    가능하시다면 쿼리를 변경하여 Test 부탁 드립니다.

  • ?
    안지민 2012.08.29 20:00

    static이 뭔지 잘 모르겠네요... 바인드를 쓰지 않는다는 의미시면


    getJdbcTemplate().update(

    new PreparedStatementCreator() {

    public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

    PreparedStatement ps = con.prepareStatement("INSERT INTO test_tbl(" +

    "tt_str, " +

    "tt_dt" +

    ") VALUES(" +

    "'test', " +

    "sysdate" +

    ")",

    Statement.RETURN_GENERATED_KEYS

    );

    return ps;

    }

    },

    generatedKeyHolder

    );



    이렇게 해봤지만 동일 하네요.

    아니면 혹시 PreparedStatement 가 아니라 Statement를 쓰라는 의미이시면...
    spring에 GeneratedKeyHolder를 사용하려면 반드시 PreparedStatement를 사용해야만 하는것으로 알고 있습니다.


  1. CUBRID 사용자를 위한 DBeaver 도구 출시 안내

    Date2024.04.23 Byadmin Views104
    read more
  2. SQLGate for CUBRID 영구 무료 라이선스 제공

    Date2020.04.09 Byadmin Views4468
    read more
  3. 큐브리드 시작시 local host 연결이 안됩니다 ㅠㅠ

    Date2012.10.07 Bythiago Views8434
    Read More
  4. CentOS 레포지토리 제공 좀 해주시면 좋겠습니다.

    Date2012.10.02 Byviper9 Views7185
    Read More
  5. 쿼리좀 도와주세요

    Date2012.09.27 By박수 Views6366
    Read More
  6. 언로드 후, 로드 시 데이터 정렬 순서가 역방향으로 바뀌는 것 관련해서...

    Date2012.09.24 By차오이 Views7124
    Read More
  7. 컴퓨터 메모리 증가 현상 문의드립니다

    Date2012.09.23 By파파후드 Views10834
    Read More
  8. 로그인 에러 문의 드립니다.

    Date2012.09.21 By낭군 Views7785
    Read More
  9. cubrid log message 관련 질문입니다.

    Date2012.09.17 By깽즈야 Views5850
    Read More
  10. 볼륨 자동 추가 기능이 작동하지 않는 것 같습니다.

    Date2012.09.14 Bynimbus89 Views5701
    Read More
  11. 큐브리드의 이전 버전 다운로드에 대해서

    Date2012.09.13 ByDiaBlue Views5555
    Read More
  12. 테이블 크기제한은 어떻게 해제하나요?

    Date2012.09.10 By로닥 Views5576
    Read More
  13. cubrid 복구 관련 문의

    Date2012.09.07 By깽즈야 Views7812
    Read More
  14. 큐브리드 매니저 질의 실행계획 표시 오류??

    Date2012.09.07 By종이 Views5486
    Read More
  15. master process에 대해서

    Date2012.09.06 By깽즈야 Views5783
    Read More
  16. 혹시 큐브리드매니저 자동완성 끄는 기능 있나요

    Date2012.09.05 By안지민 Views6037
    Read More
  17. CCI API가 Thread Safe 한가요?

    Date2012.09.04 Bynimbus89 Views7284
    Read More
  18. CCI API로 구현시 DB를 원격에서 접속할 때 발생하는 문제

    Date2012.09.01 Bynimbus89 Views5989
    Read More
  19. 명령창(커멘드 라인)으로 DB 생성시 볼륨 자동 추가 설정 방법 문의

    Date2012.09.01 Bynimbus89 Views6784
    Read More
  20. 표준프레임워크의 공통컴포넌트에 게시판설치관련

    Date2012.08.31 By큐브리 Views22768
    Read More
  21. cubrid ha 백업 문의

    Date2012.08.30 By깽즈야 Views5959
    Read More
  22. cubrid manager 접속 오류와 관련하여

    Date2012.08.30 Bybizsp Views5766
    Read More
Board Pagination Prev 1 ... 132 133 134 135 136 137 138 139 140 141 ... 200 Next
/ 200

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales