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를 사용해야만 하는것으로 알고 있습니다.


List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 CUBRID 사용자를 위한 DBeaver 도구 출시 안내 admin 2024.04.23 51
공지 SQLGate for CUBRID 영구 무료 라이선스 제공 file admin 2020.04.09 4458
1315 설치후 오류 메시지 3 moon 2014.12.10 5257
1314 성능 측정 문의 드립니다. 1 끌레도르 2015.07.10 3754
1313 성능에 관해서 질문드립니다. 5 secret 오니오니 2013.03.12 12
1312 성능평가 관련 질문 & 로드(load) 2 지용 2009.08.07 8656
1311 세그먼트 3 file 큐브리드사랑 2016.03.07 6290
1310 세로 데이터를 가로로 출력 문의 2 jjobi 2010.11.20 14268
1309 세로로 나온 레코드를 하나의 컬럼 담고 싶습니다. (긴급)(폭스소프트) 2 돌돌이 2009.03.26 14501
1308 센트OS에서 큐브리드 명령어 사용?? 7 푸른잔디 2009.12.01 12821
1307 소대문자 검색 1 잡초1 2015.05.27 4963
1306 소수에대한 업데이트가 오동작합니다. 5 kkndo2 2014.11.18 4552
1305 소스 코드 1 소라게 2013.02.09 7560
1304 속도 개선 문의 1 jkmmmm 2020.06.04 832
1303 솔라리스 사용 가능 버전 1 CUCUCUCU 2015.10.23 4722
1302 숫자 컬럼 검색 문의드립니다. 5 starworld 2018.03.06 718
1301 쉘스크립트에서 큐브리드 접속 1 susu 2022.06.09 230
1300 쉘스크립트파일이 cron으로는 실행이 되지않습니다. 2 secret 어려운큐브 2011.10.05 10
1299 스케줄러 관련 질문 4 늅늅 2022.08.01 233
1298 스크립트와 cubrid manager 어떤게 문제 일까요? 1 윈디 2022.02.18 86
1297 스키마 load 에러 1 chocob 2014.05.21 7496
1296 스키마 내려받기 문의 3 ozro 2022.10.24 68
Board Pagination Prev 1 ... 130 131 132 133 134 135 136 137 138 139 ... 200 Next
/ 200

Contact Cubrid

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