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 119
공지 SQLGate for CUBRID 영구 무료 라이선스 제공 file admin 2020.04.09 4475
1740 분할테이블 인덱스 조회시 오류입니다. 3 종이 2016.01.21 6459
1739 ADO.NET cascci.dll 64Bit, field name/type 오류 2 할리 2016.01.21 6629
1738 데이터 볼륨 정리 1 청백-e 2016.01.22 6819
1737 virtual memory 1 life 2016.01.26 6181
1736 큐브리드 설치 cubrid service start 안됨 1 secret Hera 2016.01.27 4
1735 윈도우 설치후 실행 1 file Hera 2016.01.27 6254
1734 [긴급요청] .net 에서 데이터 insert 시 cubrid manager에서 한글 깨짐 현상 문의 4 minimin0516 2016.01.28 6865
1733 마이그레이션 문의 2 joke7 2016.01.28 6751
1732 호스트 연결 에러 3 secret PJEPJE 2016.01.28 10
1731 CUBRIDbin 폴더에 생성 되는 dmp 파일 관련하여 확인 부탁드립니다. 1 secret 질의응답요청 2016.01.28 23
1730 테이블단위로 이관 3 secret 이호영 2016.01.29 14
1729 [PHP]CUBRID 연결 문제 6 php_user2 2016.01.29 6901
1728 큐브리드 연동 중 Unable to get shard id. No hint available. 에러가 발생합니다. 3 secret 호잉호잉호 2016.02.06 9
1727 질의 자동화 실행 주기 관련 문의 1 종이 2016.02.11 5953
1726 HA구성에서 파티션 적용가능? 1 라면 2016.02.12 6362
1725 oracle 마이그레이션 툴 이용 중 문제점에 대해 문의드립니다. 1 file 태진 2016.02.15 6670
1724 특정값으로 문자열을 분리하려고 합니다 1 secret 이호영 2016.02.15 8
1723 큐브리드 에러 관련 문의 입니다. 1 file 그러게 2016.02.15 5994
1722 큐브리드 사용한 데이터 구축 시 시간이 너무 오래 걸립니다. 2 file lhb 2016.02.15 7581
1721 리눅스에서 cubrid 명령어 찾을수 없는현상 3 라면 2016.02.16 8708
Board Pagination Prev 1 ... 109 110 111 112 113 114 115 116 117 118 ... 200 Next
/ 200

Contact Cubrid

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