Background Image
조회 수 31343 추천 수 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. 2010 공개SW 신뢰성 Test 결과보고서

    Date2010.12.24 Bycubrid Views20540
    Read More
  2. APC_Install-tools 1.4

    Date2009.03.13 ByPrototype Views17270
    Read More
  3. APMSETUP 6: Apache+PHP+CUBRID를 한번의 실행으로......

    Date2009.06.02 By정병주 Views39911
    Read More
  4. Autoset 4.3.2

    Date2009.03.11 ByPrototype Views26095
    Read More
  5. C++빌더 사용자를 위한 CUBRID ADO Connection 샘플

    Date2009.05.03 ByPrototype Views21534
    Read More
  6. CCI LIBRARY FOR DELPHI

    Date2009.07.01 ByPrototype Views18819
    Read More
  7. CUBRID 2008 NBD Bench 시험 결과 보고서

    Date2008.12.09 Byadmin Views46415
    Read More
  8. CUBRID AppsPack for VM

    Date2009.10.16 By시난 Views21013
    Read More
  9. CUBRID 기반의 오픈소스 툴 사용 가이드

    Date2009.04.18 Byadmin Views21923
    Read More
  10. CUBRID 매니저 아이콘 디자인 자료

    Date2009.05.15 By정병주 Views25221
    Read More
  11. CUBRID 소개 및 발전 계획

    Date2010.12.02 Bycubrid Views20454
    Read More
  12. CUBRID 지원 텍스트큐브(Textcube) 다운로드

    Date2009.07.01 By정병주 Views25614
    Read More
  13. HDD vs. SSD에서의 DBMS (CUBRID, MySQL) 성능 비교 자료

    Date2010.08.26 By정병주 Views34117
    Read More
  14. ITrack (Issue Tracking System) 이란?

    Date2006.09.06 By관리자 Views18410
    Read More
  15. ITrack KLDP에 공개SW 프로젝트로 등록

    Date2006.09.12 By김평철 Views16931
    Read More
  16. ITrack SW 다운로드

    Date2006.09.07 By관리자 Views17577
    Read More
  17. ITrack 모범 사용(best practice) 문서

    Date2006.09.07 By관리자 Views14018
    Read More
  18. ITrack 설명서

    Date2006.09.07 By관리자 Views15015
    Read More
  19. JCO 8차 컨퍼런스 발표 자료 (개발프로세스)

    Date2007.02.12 By김평철 Views17920
    Read More
  20. JDBC sample 프로그램입니다

    Date2007.10.25 By관리자 Views31343
    Read More
Board Pagination Prev 1 2 3 4 Next
/ 4

Contact Cubrid

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