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
1874 차기버전은 언제 나오나요?? 1 유니콘 2014.05.08 6237
1873 프로시저 unload 문의 1 chocob 2014.06.19 6233
1872 OLEDB 연결시 에러 db_e_sec_auth_failed ( 0x80040E4D ) 1 BlueHeart 2014.07.07 6231
1871 오라클 object_type 조회 1 김진호 2014.07.24 6230
1870 데이터베이스명 최대 자리수 관련입니다. 3 종이 2012.12.04 6224
1869 CUBRID/bin 폴더에 생성 되는 dmp 파일 관련하여 문의드립니다. 3 질의응답요청 2014.12.19 6221
1868 정기 교육 관련 문의 드립니다. 1 kings 2012.06.22 6205
1867 JDBC(MySQL) 에서 JDBC로 마이그레이션 3 file 날아라수호야 2015.04.02 6200
1866 멀티스레드 환경에서 update 문의 3 발돋움 2014.11.03 6197
1865 CUBRID 성능관련 문의 드립니다. 1 file appman 2014.09.01 6189
1864 컬럼 종류 1 file 소라게 2013.02.14 6184
1863 virtual memory 1 life 2016.01.26 6181
1862 큐브리드 사용 중 문제가 발생하였습니다. 1 file 도린아빠 2015.10.06 6181
1861 어떤 오류로그 인지 답변 좀 부탁드립니다. file 김상윤 2013.03.20 6173
1860 DB와 BROKER 분리 설정 방법 1 땡글이와밍크 2015.03.26 6171
1859 DB 컴퓨터 재부팅후 자동재실행 방법좀 알려주세요 1 오명일 2015.09.09 6163
1858 Oracle SQL to Cubrid SQL 1 적막한밤 2014.07.30 6159
1857 R2.2 에서 트랜잭션과 inser_id() 1 파스크란 2014.03.03 6156
1856 cubrid 업그레이드관련 문의합니다. 1 발칙한녀석 2014.04.19 6152
1855 그냥 궁금해서요 ^^ 1 유니콘 2012.10.16 6147
Board Pagination Prev 1 ... 102 103 104 105 106 107 108 109 110 111 ... 200 Next
/ 200

Contact Cubrid

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