Background Image

FORUM

조회 수 8916 추천 수 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
번호 제목 글쓴이 날짜 조회 수
공지 SQLGate for CUBRID 영구 무료 라이선스 제공 file admin 2020.04.09 4275
1856 쿼리 브라우저 실행 오류 1 이현세 2014.06.12 11466
1855 자바 함수 문제 현상 1 secret 배운다큐브 2014.06.11 10
1854 8.2.2 버젼 PHP 트랜잭션관련 문의드립니다. 2 secret 반짝이 2014.06.11 7
1853 cub_cmserver 프로세스가 죽어요 3 secret 배운다큐브 2014.06.11 15
1852 StoredProcedure 한글 문제 및 getConnection 문제 4 조경석 2014.06.11 9391
1851 서버에서 unload한 후 PC에서 load할때 데이타유실 발생합니다. 1 어려운큐브 2014.06.10 6825
1850 구버전 드라이버 이용 관련 문의 1 enak 2014.06.07 5427
1849 migration tool에서 오브젝트 파일 생성시 문제 1 chocob 2014.06.05 5439
1848 KEEP_CONNECTION 설정 문의 1 배여사남편 2014.05.29 6877
1847 System.Data.OleDb.OleDbException (0x80004005): Cannot communicate with server 오류 4 나이젤 2014.05.28 9678
1846 spring cubrid 연동 에러 1 chocob 2014.05.28 12568
1845 jboss 7.1 + cubrid 연동문의 1 khs0324 2014.05.26 10483
1844 csql exit code관련 1 월레스 2014.05.26 6873
1843 큐브리드 매니저 접속 안되고 있습니다. 5 file 한걸음 2014.05.23 9714
1842 Java 저장 함수 안되는 경우가 있군요. 1 루기 2014.05.23 6281
1841 CCI API 에서 LNK 2019문제가 계속 발생합니다 1 poipoi 2014.05.22 10577
1840 큐브리드 버전 정보 3 secret 소금인형 2014.05.21 10
1839 mdbc 문의 1 chocob 2014.05.21 6307
1838 CUBRID 자동 실행 1 조금느린아이 2014.05.21 6257
1837 스키마 load 에러 1 chocob 2014.05.21 7495
Board Pagination Prev 1 ... 102 103 104 105 106 107 108 109 110 111 ... 199 Next
/ 199

Contact Cubrid

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