::: 강좌/소스/문서 :::

강좌/소스/문서 성격에 맞지 않는 광고,비방,질문의 글은 즉시 삭제하며
내용을 복사하여 사용할 경우 반드시 이곳(http://www.howto.pe.kr)을 출처로 명시하여 주세요


Category

  신훈재(2004-06-18 13:43:13, Hit : 5796, Vote : 1423
 [자바] JDBC 테스트 소스(오라클)

[ JDBC 테스트 소스 ]


1. 단순히 오라클 DB에 연결되는지 테스트하는 어플리케이션
---------------------------------------------------------------------
import java.sql.*;

public class TestJdbc
{
        public static void main ( String args [] )
        {
                Connection con;
                try
                {
                        Class.forName ( "oracle.jdbc.driver.OracleDriver" );            
                        System.out.println ( "1: Driver Loading Successful..." );
                        
                        String url = "jdbc:oracle:thin:@192.168.1.103:1521:ORCL";
                        con = DriverManager.getConnection ( url, "scott", "tiger" );
                        System.out.println ( "2: Connect Successful..." );
                        
                        con.close ( );
                        System.out.println ( "3: Connect Close Successful..." );
                }
                catch ( Exception e ) { System.out.println ( "4: Connection Error..." ); }
        }
}

/*
결과
1: Driver Loading Successful...
2: Connect Successful...
3: Connect Close Successful...
*/
---------------------------------------------------------------------

2. 오라클 DB에 연결하고 테이블의 값을 가져오는지 테스트하는 어플리케이션
---------------------------------------------------------------------
import java.sql.*;

public class TestJdbc
{
        public static void main ( String args [] )
        {
                try
                {
                        Class.forName ( "oracle.jdbc.driver.OracleDriver" );            
                        System.out.println ( "1: Driver Loading Successful..." );
                        
                        String url = "jdbc:oracle:thin:@192.168.1.103:1521:ORCL";
                        Connection conn = DriverManager.getConnection ( url, "scott", "tiger" );
                        System.out.println ( "2: Connect Successful..." );
                        
                        PreparedStatement stmt = conn.prepareStatement ( "select * from dept" );
                        ResultSet rset = stmt.executeQuery ( );
                        System.out.println ( "3: DB Query Send or Receive Successful..." );
                        
                        while ( rset.next ( ) )
                        {
                                System.out.print ( "- " + rset.getString ( 1 ) + " - " );
                                System.out.print ( rset.getString ( 2 ) + " - " );
                                System.out.println ( rset.getString ( 3 ) + " - " );
                        }
                        
                        rset.close ( );        
                        stmt.close ( );
                        conn.close ( );
                        System.out.println ( "4: Connect Close Successful..." );
                }
                catch ( Exception e ) { System.out.println ( "5: Connection Error..." ); }
        }
}

/*
결과
1: Driver Loading Successful...
2: Connect Successful...
3: DB Query Send or Receive Successful...
- 10 - ACCOUNTING - NEW YORK -
- 20 - RESEARCH - DALLAS -
- 30 - SALES - CHICAGO -
- 40 - OPERATIONS - BOSTON -
4: Connect Close Successful...
*/
---------------------------------------------------------------------

3. 오라클 DB에 연결하고 테이블의 값을 가져오는지 테스트하는 Jsp
---------------------------------------------------------------------
<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.sql.*, java.util.*, java.lang.*" %>

<html>
<head><title></title>
</head>
<body>
<table border=1>

<%
        Class.forName ( "oracle.jdbc.driver.OracleDriver" );
        
        Connection conn = DriverManager.getConnection ( "jdbc:oracle:thin:@192.168.1.103:1521:ORCL", "scott", "tiger" );
        PreparedStatement stmt = conn.prepareStatement ( "select * from dept" );
        ResultSet rset = stmt.executeQuery ( );
          
        while ( rset.next ( ) )
        {
%>

<tr><td><%=rset.getString(1)%></td><td><%=rset.getString(2)%></td><td><%=rset.getString(3)%></td></tr>

<%
        }        
        rset.close ( );        
        stmt.close ( );
        conn.close ( );
%>

</table>
</body>
</html>

<!--
결과:
    10         ACCOUNTING     NEW YORK
    20         RESEARCH       DALLAS
    30         SALES          CHICAGO
    40         OPERATIONS     BOSTON  
//-->
---------------------------------------------------------------------








183   [네트워크/보안] [참고] 다중연결(multiple sockets) 서버의 구현방법 종류  김영대 2003/07/17 10414 2177
182   [네트워크/보안] [참고] TCP 에서 사용되는 효율향상 알고리즘  김영대 2004/07/16 10229 2032
181   [네트워크/보안] [참고] TCP 에서 사용되는 내부 타이머  김영대 2004/07/13 10099 1861
180   [Java/PHP] [자바] 활용팁(오라클)  신훈재 2004/06/18 6360 1679
179   [Java/PHP] [자바] 오라클 각종 에러  신훈재 2004/06/18 6918 1926
178   [Java/PHP] [자바] 여러종류의 데이타베이스 테스트 소스  신훈재 2004/06/18 7029 1550
177   [Java/PHP] [자바] 시스템 프로퍼티를 이용한 드라이버 로드  신훈재 2004/06/18 5845 1511
176   [Java/PHP] [자바] Update예제  신훈재 2004/06/18 5772 1427
175   [Java/PHP] [자바] Select예제  신훈재 2004/06/18 8477 1640
174   [Java/PHP] [자바] ResultSet 질의결과  신훈재 2004/06/18 6485 1392
173   [Java/PHP] [자바] Query Statement  신훈재 2004/06/18 8210 1571
172   [Java/PHP] [자바] JDBC-ODBC 연결 예제  신훈재 2004/06/18 10467 1779
  [Java/PHP] [자바] JDBC 테스트 소스(오라클)  신훈재 2004/06/18 5796 1423
170   [Java/PHP] [자바] JDBC 코딩시 주위사항(jsp, servlet)  신훈재 2004/06/18 8024 1451
169   [Java/PHP] [자바] JDBC Connect  신훈재 2004/06/18 11078 1583
168   [Java/PHP] [자바] Insert 예제  신훈재 2004/06/18 6858 1765
167   [Java/PHP] [자바] DB 컨넥션 풀  신훈재 2004/06/18 10323 1973
166   [Delphi] [소스] 한글이 들어있는 문자열에서 초성 음소로 검색하기  김영대 2004/10/23 10354 2198
165   [Delphi] [소스] 하루에 한번씩 자동으로 배경화면 바꾸기  김영대 2003/03/12 7467 1706
164   [Delphi] [소스] 폼의 내용을 그대로 저장하고 복원하는 콤포넌트  김영대 2003/03/12 7099 1741

1 [2][3][4][5][6][7][8][9][10]
 

Copyright 1999-2020 Zeroboard / skin by zero