Background Image

FORUM

조회 수 382 추천 수 0 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

* 질문 등록 시 다음의 내용을 꼭 기입하여 주세요.
OS
Linux 64bit 등
CUBRID Ver.
10.1
CUBRID TOOL Ver.
10.1.0.0003 
응용 환경(API)
java

* CUBRID 응용 오류, SQL 오류 또는 SQL 튜닝 관련된 문의는 반드시 다음의 내용을 추가해 주세요. 비밀글이나 비밀 댓글도 가능합니다.
* 저희가 상황을 이해하고, 재현이 가능해야 알 수 있는 문제들이 많습니다. 가능한 정보/정황들을 부탁합니다.
에러 내용 및 재현 방법 재현 가능한 Source와 SQL
관련 테이블(인덱스, 키정보 포함) 정보 CUBRID 홈 디렉토리 아래 log 디렉토리 압축


-------------- 아래에 질문 사항을 기입해 주세요. ------------------------------------------------------------------------
프로시져를 작성하였는데 궁금한 점 2가지 문의 드립니다.


=============== 테이블 스키마 ======================

CREATE TABLE [ta_seq] (

[bplc_cd] CHARACTER VARYING (11) NOT NULL COMMENT '사업소코드',

[biz_cd] CHARACTER VARYING (2) NOT NULL COMMENT '업무코드',

[seq] INTEGER COMMENT '순번',

CONSTRAINT [ta_seq_pk] PRIMARY KEY([biz_cd], [bplc_cd]),

CONSTRAINT [ta_seq_idx] UNIQUE KEY([biz_cd], [bplc_cd])

)

COLLATE euckr_bin

COMMENT = '순번';


===================== 프로시저 코드(JAVA) ========================


import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;


public class Sproc {

public static void getIndex(String pBplCd, String pBizCd, Integer vnCount) throws Exception

{

Connection conn = null;

PreparedStatement pstmt = null;

vnCount = 0;

String sql = "";

try {

try {

Class.forName("cubrid.jdbc.driver.CUBRIDDriver");

} catch (ClassNotFoundException e) {

System.out.println("Driver Class Not Found");

}

conn = DriverManager.getConnection("jdbc:default:connection:");

vnCount = getIndexNumber(conn, pBplCd, pBizCd);

System.out.println("프로시저 리턴 결과 vnCount : " + vnCount);

if(vnCount == null)

{

throw new Exception("getIndexNumber value is null");

}

if(vnCount == 0)

{

System.out.println("==================== 조건 1 ========================");

sql = "INSERT INTO TA_SEQ(BPLC_CD, BIZ_CD, SEQ)VALUES(?, ?, ?)";

pstmt = conn.prepareStatement(sql);

pstmt.setString(1, pBplCd);

pstmt.setString(2, pBizCd);

pstmt.setInt(3, 1);

pstmt.executeUpdate();

}

else

{

System.out.println("==================== 조건 2 ========================");

sql = "UPDATE TA_SEQ SET SEQ = ? WHERE BPLC_CD = ? AND BIZ_CD = ?";

pstmt = conn.prepareStatement(sql);

pstmt.setString(1, pBplCd);

pstmt.setString(2, pBizCd);

pstmt.setInt(3, vnCount + 1);

pstmt.executeUpdate();

}

vnCount += 1;

System.out.println("==================== 최종결과 vnCount :  ========================" + vnCount);

pstmt.close();

conn.commit();

conn.close();

}catch(SQLException e) {

System.err.println(e.getMessage());

vnCount = null;

}finally {

if(pstmt != null)try {pstmt.close();}catch(SQLException ex) {}

if(conn != null)try {conn.close();}catch(SQLException ex) {}

}

}

public static Integer getIndexNumber(Connection conn, String pBplCd, String pBizCd)

{

System.out.println("============================== 호출  시작 ============================");

System.out.println("pBplCd : " + pBplCd);

System.out.println("pBizCd : " + pBizCd);

System.out.println("============================== 호출 종료 ============================");

PreparedStatement pstmt = null;

ResultSet rs = null;

Integer vnCount = 0;

String sql = "SELECT IFNULL(SEQ, 0) FROM TA_SEQ WHERE BPLC_CD = ? AND BIZ_CD = ?";

try {

pstmt = conn.prepareStatement(sql);

pstmt.setString(1, pBplCd);

pstmt.setString(2, pBizCd);

rs = pstmt.executeQuery();

while(rs.next())

{

vnCount = rs.getInt("SEQ");

}

rs.close();

pstmt.close();

}catch(SQLException e) {

System.err.println(e.getMessage());

vnCount = null;

}finally {

if(rs != null)try {rs.close();}catch(SQLException ex) {}

if(pstmt != null)try {pstmt.close();}catch(SQLException ex) {}

}

return vnCount;

}

}


================================ 프로시저 등록 ================================

Sproc.java loadjava 를 이용하여 등록한 상태

CREATE PROCEDURE getIndex(p_bplc_cd IN varchar, p_biz_cd IN VARCHAR, p_seq OUT INTEGER) 

AS LANGUAGE JAVA NAME 'Sproc.getIndex(java.lang.String, java.lang.String, java.lang.Integer)';


============================= 호출 자바 샘플 ======================================



import java.sql.CallableStatement;

import java.sql.Connection;

import java.sql.DriverManager;


public class Test {


public static void main(String[] args) throws Exception{

String url = "jdbc:cubrid:192.168.195.100:33000:kioskdb:::?charSet=EUC-KR";

String userid = "kioskcub";

String password = "kioskcubpwd";

Class.forName("cubrid.jdbc.driver.CUBRIDDriver");

Connection conn = DriverManager.getConnection(url, userid, password);

CallableStatement ctmt;

ctmt = conn.prepareCall(" call getIndex(?, ?, ?)" ) ;

ctmt.setString(1, "MASTER");

ctmt.setString(2, "99");

ctmt.registerOutParameter(3, java.sql.Types.INTEGER);

ctmt.execute() ;

int cnt = ctmt.getInt(3);

System.out.println(cnt);

}


}


========================================== 실행결과 ============================


============================== 호출  시작 ============================

pBplCd : MASTER

pBizCd : 99

============================== 호출 종료 ============================

프로시저 리턴 결과 vnCount : 0

==================== 조건 1 ========================

==================== 최종결과 vnCount :  ========================1


제가 기대했던 결과는 TA_SEQ 테이블에 데이터가 없기 때문에 INSERT 가 되고 int cnt = ctmt.getInt(3); 가 1이 리턴되는걸 예상했는데 테이블에는 데이터가 

들어가지도 않고   int cnt = ctmt.getInt(3); 값은 계속 0 이 됩니다.

어디가 잘못되었는지 몰라서 문의 드립니다.


  • ?
    엄기호 2018.05.29 16:12
    sql_log 정보를 보시면 어떤 질의문이 에러가 났는지 알 수 있을 겁니다.
    sql_log 위치는 log/broker/sql_log에 있습니다.
    리눅스 임으로 cd명령어를 이용하여 sql_log 위치로 이동하여 파일을 열어서 확인 해보십시요..
    #>cd $CUBRID/log/broker/sql_log 엔터

  1. CUBRID 사용자를 위한 DBeaver 도구 출시 안내

    Date2024.04.23 Byadmin Views51
    read more
  2. SQLGate for CUBRID 영구 무료 라이선스 제공

    Date2020.04.09 Byadmin Views4458
    read more
  3. 큐브리드 매니저(cubrid manager)에서 원격 호스트 접속이 안됩니다.

    Date2018.06.11 Byym Views912
    Read More
  4. python에서 cubrid 사용시 권한문제 질문드립니다

    Date2018.06.11 Bywooks Views1121
    Read More
  5. DECODE 함수 사용시 문제 발생건

    Date2018.06.07 By지성 Views1156
    Read More
  6. is not defined 에러

    Date2018.05.30 ByJSP초보입니당 Views1185
    Read More
  7. character varying" to domain "date" 오류

    Date2018.05.30 By리안커 Views1925
    Read More
  8. DB 테이블 목록 등 열기 시 오류 (+로그 추가-2)

    Date2018.05.29 Bycacaopie Views464
    Read More
  9. 테이블 설명 기능 설치

    Date2018.05.29 Byabg Views300
    Read More
  10. Store Procedure 작성 관련 질문

    Date2018.05.28 By키레이니 Views382
    Read More
  11. Store Procedure 호출 관련 질문

    Date2018.05.28 By키레이니 Views508
    Read More
  12. comment 기능 질문

    Date2018.05.25 By키레이니 Views750
    Read More
  13. heap_get_visible_version_from_log 에러

    Date2018.05.24 By복분자 Views275
    Read More
  14. FATAL ERROR 발생으로 cubrid server start가 되지 않습니다.

    Date2018.05.24 By복분자 Views1265
    Read More
  15. cubrid server start: fail 이 뜹니다.

    Date2018.05.24 By복분자 Views2091
    Read More
  16. create db 실행 오류

    Date2018.05.22 By영진 Views611
    Read More
  17. 오라클 job -> 큐브리드 ??

    Date2018.05.17 By퓨전남 Views485
    Read More
  18. 툴에서 튜닝모드로 수행했을 때 관련

    Date2018.05.16 By잉여개발자 Views330
    Read More
  19. cubrid.jdbc.driver.CUBRIDException: Semantic: Cannot coerce host var to type bit. 문의 드립니다.

    Date2018.05.16 Byvks Views2866
    Read More
  20. 트리거 질문입니다.

    Date2018.05.15 By퓨전남 Views738
    Read More
  21. 안녕하세요.. 초보적인 질문입니다,

    Date2018.05.15 ByMi Views180
    Read More
  22. 하이버네이트 uniqueResult 함수 사용 문의

    Date2018.05.15 Bykim77p Views461
    Read More
Board Pagination Prev 1 ... 54 55 56 57 58 59 60 61 62 63 ... 200 Next
/ 200

Contact Cubrid

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