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 php 모듈 설치 에러입니다 1 secret 럭키늘보 2010.05.08 13
1873 php 모듈 설치 에러입니다 2 터프키드 2009.07.30 9431
1872 php 모듈 로드가 안됩니다. 3 김우람 2011.11.11 14354
1871 php 모듈 로드 문제 입니다. 2 하하보이 2011.06.28 9267
1870 php 모듈 관련해서 의견을 구합니다. 2 potter 2009.12.03 8767
1869 php 모듈 관련 문제좀여... 5 눈뜨면아침 2012.03.01 7126
1868 php 모듈 5 sakang 2009.02.24 17018
1867 php pdo_cubrid 실행이 안됩니다. 6 file smilena 2021.04.27 299
1866 php glo 접근 질문. 1 송효진 2009.04.05 16621
1865 php driver interface...x64 4 platanus 2011.07.08 7661
1864 php cubrid_driver 설치 에러 1 jslee 2022.04.23 299
1863 php cubrid_bind() 에 관하여. 1 송효진 2009.04.05 11440
1862 php cubrid extension 문의 입니다 - 4 김은호 2009.06.10 18514
1861 php 7용 큐브리드 드라이버 지원 문의 2 차오이 2017.07.05 414
1860 php 7.4 접속 에러 16 file jslee 2022.04.27 171
1859 php 7.3 버전에도 설치가 가능한가요 ? 1 kks8017 2019.07.31 156
1858 php 7.3 + Cubrid 8.4.4 연동 문제 1 땡땡이 2021.06.08 86
1857 php 5.3.1 / php extension 컴파일 오류 있네요... 1 disablerain 2009.12.11 17729
1856 php 5.1.6 연동 문제 3 올닉스 2011.01.01 10228
1855 php - cubird 연결 부분 오류 문제 문의 드립니다. 3 file 김우람 2011.05.19 34353
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