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

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


Category

  신훈재(2004-06-18 13:43:13, Hit : 5436, Vote : 1345
 [자바] 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  
//-->
---------------------------------------------------------------------








23   [Java/PHP] [자바] DB 컨넥션 풀  신훈재 2004/06/18 9511 1857
22   [Java/PHP] [자바] JDBC-ODBC 연결 예제  신훈재 2004/06/18 9046 1672
21   [Java/PHP] [자바] 시스템 프로퍼티를 이용한 드라이버 로드  신훈재 2004/06/18 5487 1425
20   [Java/PHP] [자바] 오라클 각종 에러  신훈재 2004/06/18 6490 1671
19   [Java/PHP] [자바] 활용팁(오라클)  신훈재 2004/06/18 5997 1603
18   [Java/PHP] [자바] ResultSet 질의결과  신훈재 2004/06/18 6111 1317
17   [Java/PHP] [자바] Select예제  신훈재 2004/06/18 6250 1562
16   [Java/PHP] [자바] Update예제  신훈재 2004/06/18 5414 1333
15   [Java/PHP] [자바] Insert 예제  신훈재 2004/06/18 6493 1673
14   [Java/PHP] [자바] Query Statement  신훈재 2004/06/18 7763 1468
13   [Java/PHP] [자바] JDBC Connect  신훈재 2004/06/18 6718 1489
12   [Java/PHP] [자바] JDBC 코딩시 주위사항(jsp, servlet)  신훈재 2004/06/18 6138 1357
11   [Java/PHP] [자바] 여러종류의 데이타베이스 테스트 소스  신훈재 2004/06/18 6421 1457
  [Java/PHP] [자바] JDBC 테스트 소스(오라클)  신훈재 2004/06/18 5436 1345
9   [Java/PHP] [소스] snmp 를 이용한 시스템 가용율 구하기 예제  김영대 2003/12/01 9570 2092
8   [Java/PHP] [소스] Oolong 언어를 이용한 Factorial 계산 프로그램 예제  김영대 2003/11/10 6633 1683
7   [Java/PHP] [문서] Java Web Services Development Pack (JWSDP) 1.0 tutorial  김영대 2003/03/24 5851 1457
6   [Java/PHP] [문서] Java Swing v1.1.1 도움말  김영대 2003/03/24 5782 1470
5   [Java/PHP] [문서] Java Servlet Development Kit (JSDK) v2.3 도움말  김영대 2003/03/24 5520 1454
4   [Java/PHP] [문서] Java 2 SDK, Enterprise Edition (J2EE) 1.3.1 도움말  김영대 2003/03/24 5617 1469

1 [2]
 

Copyright 1999-2017 Zeroboard / skin by zero