Background Image
조회 수 30805 추천 수 136 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 수정 삭제
기본적인 JDBC 응용 샘플입니다.

수행하시려면 서버 주소/포트/DB명등을 고치시고 해보세요.
프로그램 구조는 클래스를 만들고
Prepare문을 통해 질의를 수행하고
Rollback으로 수행을 취소시키는 구조입니다.


import java.util.*;
import java.sql.*;

public class basic {

public static Connection connect() {
Connection conn = null;
try {
Class.forName("cubrid.jdbc.driver.CUBRIDDriver");
conn = DriverManager.getConnection("jdbc:cubrid:192.168.1.1:30000:testdb:dba::","dba","");
conn.setAutoCommit (false) ;
} catch ( Exception e ) {
System.err.println("SQLException : " + e.getMessage());
}
return conn;
}

public static void printdata(ResultSet rs) {
try {
ResultSetMetaData rsmd = null;

rsmd = rs.getMetaData();
int numberofColumn = rsmd.getColumnCount();

while (rs.next ()) {
for(int j=1; j<=numberofColumn; j++ )
System.out.print(rs.getString(j) + " " );
System.out.println("");
}
} catch ( Exception e ) {
System.err.println("SQLException : " + e.getMessage());
}
}

public static void main(String[] args) throws Exception {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement preStmt = null;

try {
conn = connect();

stmt = conn.createStatement();
stmt.executeUpdate("create class xoo ( a int, b int, c char(10))");

preStmt = conn.prepareStatement("insert into xoo values(?,?,''''100'''')") ;
preStmt.setInt (1, 1) ;
preStmt.setInt (2, 1*10) ;
int rst = preStmt.executeUpdate () ;

rs = stmt.executeQuery("select a,b,c from xoo" );

printdata(rs);

conn.rollback();
stmt.close();
conn.close();
} catch ( Exception e ) {
conn.rollback();
System.err.println("SQLException : " + e.getMessage());
} finally {
if ( conn != null ) conn.close();
}
}
}

  1. php로 cubrid 프로시저 사용하기 2 - cubrid_prepare 이용 -

    Date2007.10.30 By박진호 Views24115
    Read More
  2. JDBC sample 프로그램입니다

    Date2007.10.25 By관리자 Views30805
    Read More
  3. [util] procedure 등록 유틸리티

    Date2007.10.19 By이지현 Views15417
    Read More
  4. phpCubAdmin 1.0.1 입니다.

    Date2007.10.18 By야라바 Views18976
    Read More
  5. loadjava GUI Tool 공유

    Date2007.10.13 By궁금이 Views19236
    Read More
  6. php로 큐브리드 프로시저 사용하기

    Date2007.10.05 By박진호 Views22497
    Read More
  7. 교육 예제입니다.

    Date2007.07.25 By강사 Views18109
    Read More
  8. 게임개발자들을 위한 CUBRID C-API 관련 자료 및 sample code

    Date2007.06.28 By남재우 Views20159
    Read More
  9. 큐브리드용 그누보드 4.21.0

    Date2007.06.22 By한마루 Views38480
    Read More
  10. PHP로 DB작업 디버깅하기(오류시 담당자에 디버깅 정보 보내기)

    Date2007.06.19 By서상욱 Views20123
    Read More
  11. 큐브리드 7.0 : cci c 파일 델파이 포팅자료 - 베타1

    Date2007.05.31 By나비스 Views16395
    Read More
  12. 사이냅소프트(Synapsoft) 개발체계

    Date2007.04.13 By정병주 Views18546
    Read More
  13. JCO 8차 컨퍼런스 발표 자료 (개발프로세스)

    Date2007.02.12 By김평철 Views17389
    Read More
  14. 소프트웨어 개발 프로세스 자료들...

    Date2007.01.17 By관리자 Views26812
    Read More
  15. 큐브리드용 제로보드 및 데이터 마이그레이션 툴

    Date2006.10.12 ByInoS Views21985
    Read More
  16. ITrack KLDP에 공개SW 프로젝트로 등록

    Date2006.09.12 By김평철 Views16419
    Read More
  17. ITrack (Issue Tracking System) 이란?

    Date2006.09.06 By관리자 Views17886
    Read More
  18. 큐브리드용 그누보드(GNUBOARD)4 공개

    Date2007.02.26 By한마루 Views1560623
    Read More
  19. ITrack 모범 사용(best practice) 문서

    Date2006.09.07 By관리자 Views13517
    Read More
  20. ITrack 설명서

    Date2006.09.07 By관리자 Views14511
    Read More
Board Pagination Prev 1 2 3 4 Next
/ 4

Contact Cubrid

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