레이블이 자바JDBC인 게시물을 표시합니다. 모든 게시물 표시
레이블이 자바JDBC인 게시물을 표시합니다. 모든 게시물 표시

2013년 11월 3일 일요일

스프링,아이바티스트랜잭션예제[Spring Framework3.X,Transaction,iBATIS, @Transactional]

스프링,아이바티스트랜잭션예제[Spring Framework3.X,Transaction,iBATIS, @Transactional]
 
스프링의 트랜잭션 관리 방법중 @Transactional 애노테이션을 이용하여 iBATIS와 연동하는 간단 예제이다.(오라클 emp 테이블에 Data 1건 insert..)

먼저 Spring MVC 프로젝트 하나 생성하자.
 
1. pom.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.mungchung</groupId>
 <artifactId>sample</artifactId>
 <name>abc</name>
 <packaging>war</packaging>
 <version>1.0.0-BUILD-SNAPSHOT</version>
 <properties>
  <java-version>1.6</java-version>
  <org.springframework-version>3.0.6.RELEASE</org.springframework-version>
  <org.aspectj-version>1.6.9</org.aspectj-version>
  <org.slf4j-version>1.5.10</org.slf4j-version>
 </properties>
 <dependencies>
 
  <!-- Spring -->
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>${org.springframework-version}</version>
   <exclusions>
    <!-- Exclude Commons Logging in favor of SLF4j -->
    <exclusion>
     <groupId>commons-logging</groupId>
     <artifactId>commons-logging</artifactId>
    </exclusion>
   </exclusions>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>${org.springframework-version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-tx</artifactId>
   <version>${org.springframework-version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-jdbc</artifactId>
   <version>${org.springframework-version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-orm</artifactId>
   <version>${org.springframework-version}</version>
  </dependency>
  <dependency>
   <groupId>org.apache.ibatis</groupId>
   <artifactId>ibatis-sqlmap</artifactId>
   <version>2.3.4.726</version>
  </dependency>
  <dependency>
   <groupId>commons-dbcp</groupId>
   <artifactId>commons-dbcp</artifactId>
   <version>1.2.2</version>
  </dependency>
  <dependency>
   <groupId>xerces</groupId>
   <artifactId>xercesImpl</artifactId>
   <version>2.9.1</version>
  </dependency>
  <dependency>
   <groupId>cglib</groupId>
   <artifactId>cglib</artifactId>
   <version>2.2</version>
   <type>jar</type>
   <scope>compile</scope>
  </dependency>
  <!-- AspectJ -->
  <dependency>
   <groupId>org.aspectj</groupId>
   <artifactId>aspectjrt</artifactId>
   <version>${org.aspectj-version}</version>
  </dependency>
  <!-- Logging -->
  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-api</artifactId>
   <version>${org.slf4j-version}</version>
  </dependency>
  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>jcl-over-slf4j</artifactId>
   <version>${org.slf4j-version}</version>
   <scope>runtime</scope>
  </dependency>
  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>${org.slf4j-version}</version>
   <scope>runtime</scope>
  </dependency>
  <dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.16</version>
   <exclusions>
    <exclusion>
     <groupId>javax.mail</groupId>
     <artifactId>mail</artifactId>
    </exclusion>
    <exclusion>
     <groupId>javax.jms</groupId>
     <artifactId>jms</artifactId>
    </exclusion>
    <exclusion>
     <groupId>com.sun.jdmk</groupId>
     <artifactId>jmxtools</artifactId>
    </exclusion>
    <exclusion>
     <groupId>com.sun.jmx</groupId>
     <artifactId>jmxri</artifactId>
    </exclusion>
   </exclusions>
   <scope>runtime</scope>
  </dependency>
  <!-- @Inject -->
  <dependency>
   <groupId>javax.inject</groupId>
   <artifactId>javax.inject</artifactId>
   <version>1</version>
  </dependency>
  <!-- Servlet -->
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>servlet-api</artifactId>
   <version>2.5</version>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>javax.servlet.jsp</groupId>
   <artifactId>jsp-api</artifactId>
   <version>2.1</version>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>jstl</artifactId>
   <version>1.2</version>
  </dependency>
  <!-- Test -->
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.7</version>
   <scope>test</scope>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>${java-version}</source>
     <target>${java-version}</target>
    </configuration>
   </plugin>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
     <warName>abc</warName>
    </configuration>
   </plugin>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
     <execution>
      <id>install</id>
      <phase>install</phase>
      <goals>
       <goal>sources</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <configuration>
     <encoding>UTF-8</encoding>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>
 

2. 컨트롤러
 
package onj.edu.transaction;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HomeController {
 @Autowired
 private TransactionMain transactionMain;

 @RequestMapping(value = "/hello", method = RequestMethod.GET)
 public String home(Locale locale, Model model) {
  String msg = "";
  try {
   msg = transactionMain.insert();
  } catch (Throwable e) {
   msg = "Transaction 오류";
   e.printStackTrace();
  }
  model.addAttribute("msg", msg );
  return "onj";
 }
}
 
3. 트랜잭션 메인 클래스
 
package onj.edu.transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
public class TransactionMain {
 @Autowired
 private Tran1 tr1;

 @Transactional(propagation = Propagation.REQUIRED)
 public String insert() throws Throwable {
  tr1.insertTest();
 
  return "Transaction Success!!";
 }
}

4. 트랜잭션 처리 클래스(간단히 EMP 테이블에 한건 인서트)

package onj.edu.transaction;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
public class Tran1 {
 @Autowired
 private SqlMapClientTemplate sqlMapClientTemplate;

 @Transactional(propagation = Propagation.REQUIRED)
 public void insertTest() {
  HashMap<String, String> hashMap = new HashMap<String, String>();
  hashMap.put("empno", "101");
  hashMap.put("ename", "오엔제이");
  sqlMapClientTemplate.insert("sql.empinsert1", hashMap);
 }
}
 
5. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring/root-context.xml</param-value>
 </context-param>


 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <servlet>
  <servlet-name>onjServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/spring/onjServlet-context.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 
 <servlet-mapping>
  <servlet-name>onjServlet</servlet-name>
  <url-pattern>*.html</url-pattern>
 </servlet-mapping>
</web-app>
 
6. /spring/root-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

 <tx:annotation-driven proxy-target-class="true"/>

 <context:component-scan base-package="onj.edu.transaction">
  <context:exclude-filter type="annotation" __EXPRESSION__="org.springframework.stereotype.Controller" />
 </context:component-scan>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  destroy-method="close">
  <property name="driverClassName">
   <value>oracle.jdbc.driver.OracleDriver</value>
  </property>
  <property name="url">
   <value>jdbc:oracle:thin:@192.168.0.7:1521:onj</value>
  </property>
  <property name="username">
   <value>scott</value>
  </property>
  <property name="password">
   <value>tiger</value>
  </property>
 </bean>
   
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation" value="classpath:/sql-map-config.xml"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>
   
    <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
        <property name="sqlMapClient" ref="sqlMapClient"/>
    </bean>
 <bean id="transactionManager"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
 </bean>
 <bean id="tr1" class="onj.edu.transaction.Tran1"/>
 <bean id="trMain" class="onj.edu.transaction.TransactionMain"/>
</beans>

7. /spring/onjServlet-context.xml

 <!-- Enables the Spring MVC @Controller programming model -->
 <annotation-driven/>
 <tx:annotation-driven proxy-target-class="true"/>
 <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
 <resources mapping="/resources/**" location="/resources/" />
 <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
 <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <beans:property name="prefix" value="/views/" />
  <beans:property name="suffix" value=".jsp" />
 </beans:bean>

 <context:component-scan base-package="onj.edu.transaction"/>

</beans:beans>
 
8. src/main/resources/sql-map-config.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
  "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
    <settings useStatementNamespaces="true"/>   
    <sqlMap resource="sqlmap/sql.xml"/>
</sqlMapConfig>

9.  SLQ매퍼, src/main/resources/sqlmap/sql.xml
 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com/DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="sql">
 <insert id="empinsert1" parameterClass="hashMap">
  INSERT INTO emp (empno, ename) VALUES (#empno#, #ename#)
 </insert>
</sqlMap>

10.마지막으로 view 역할을 하는 jsp(/views/onj.jsp)
 
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
 <title>Home</title>
</head>
<body>
//트랜잭션처리결과 출력
<P> ${msg} </P>
</body>
</html>

2013년 10월 22일 화요일

[자바상속컴포지션]Java Inheritance & Composition 상속과 컴포지션은 동전의 양면과 같이 유사하게 서로에게 관련이 있다. 상속은 마치 양파가 여러 껍질로 이루어진 것과 같이 계층화된 객체 컴포지션은 여러 재료(객체)가 한데 뭉쳐서 만들어진 죽 컴포지션은 개체들간의 'has a' 관계, 상속은 ‘is a’관계 상속과 컴포지션은 상호 배타적이지 않으며 개발자는 이 둘을 같이 사용한다. 다음 예제는 ‘is a’와 ‘has a’의 착각에는 나오게 되는 실수이다. 1. 원은 반지름 값을 갖는 하나의 점이다(a Circle is a Point with a radius.) 그래서 Circle은 Point를 상속 class Point { private double x, y; Point(double x, double y) { this.x = x; this.y = y; } double getX() { return x; } double getY() { return y; } } class Circle extends Point { private double radius; Circle(double x, double y, double radius) { super(x, y); this.radius = radius; } double getRadius() { return radius; } } 2. 원은 한 점과 반지름을 가지고 있다(a circle has a point and a radius) class Point { private double x, y; Point(double x, double y) { this.x = x; this.y = y; } //redundant code 로 인한 유지보수 어려움(코드의 재사용 실패) double getX() { return x; } double getY() { return y; } } class Circle { private Point p; private double radius; Circle(double x, double y, double radius) { p = new Point(x, y); this.radius = radius; } double getX() { return p.getX(); } double getY() { return p.getY(); } double getRadius() { return radius; } } [출처] 오라클자바커뮤니티 - http://www.oraclejavanew.kr/bbs/board.php?bo_table=LecJava&wr_id=601 오라클자바커뮤니티에서 설립한 개발자교육6년차 오엔제이프로그래밍 실무교육센터(오라클SQL,튜닝,힌트,자바프레임워크,안드로이드,아이폰,닷넷 실무개발강의) www.onjprogramming.co.kr [개강확정강좌]오라클자바커뮤니티에서 운영하는 개발자 전문교육 ,개인80%환급(www.onjprogramming.co.kr) [주말] [10/26]C#,ASP.NET마스터 [10/26]Spring3.X, MyBatis, Hibernate실무과정 [10/27]JAVA&WEB프레임워크실무과정 [평일야간] [10/29]C#,ASP.NET마스터 [10/25]Spring3.X, MyBatis, Hibernate실무과정 [10/31]JAVA&WEB프레임워크실무과정 [주간] [11/4]Spring3.X, MyBatis, Hibernate실무과정 [기타 다른 강좌는 아래 해당 카테고리를 클릭해주세요] JAVA ORACLE iPhone/Android .NET 표준웹/HTML5 채용/취업무료교육 초보자(재학생)코스

[자바상속컴포지션]Java Inheritance & Composition

상속과 컴포지션은 동전의 양면과 같이 유사하게 서로에게 관련이 있다. 
상속은 마치 양파가 여러 껍질로 이루어진 것과 같이 계층화된 객체
컴포지션은 여러 재료(객체)가 한데 뭉쳐서 만들어진 죽
컴포지션은 개체들간의 'has a' 관계, 상속은 ‘is a’관계
상속과 컴포지션은 상호 배타적이지 않으며 개발자는 이 둘을 같이 사용한다.
다음 예제는 ‘is a’와 ‘has a’의 착각에는 나오게 되는 실수이다.

1. 원은 반지름 값을 갖는 하나의 점이다(a Circle is a Point with a radius.)
   그래서 Circle은 Point를 상속

   
   
class Point {
 private double x, y;
 Point(double x, double y) {
  this.x = x;
  this.y = y;
 }
 double getX() {
  return x;
 }
 double getY() {
  return y;
 }
}
class Circle extends Point {
 private double radius;
 Circle(double x, double y, double radius) {
  super(x, y);
  this.radius = radius;
 }
 double getRadius() {
  return radius;
 }
}
 
2. 원은 한 점과 반지름을 가지고 있다(a circle has a point and a radius)
 
class Point {
 private double x, y;
 Point(double x, double y) {
  this.x = x;
  this.y = y;
 }
 //redundant code 로 인한 유지보수 어려움(코드의 재사용 실패)
 double getX() {
  return x;
 }
 double getY() {
  return y;
 }
}
 
class Circle {
 private Point p;
 private double radius;
 Circle(double x, double y, double radius) {
  p = new Point(x, y);
  this.radius = radius;
 }
 double getX() {
  return p.getX();
 }
 double getY() {
  return p.getY();
 }
 double getRadius() {
  return radius;
 }
}

오라클자바커뮤니티에서 설립한 개발자교육6년차 오엔제이프로그래밍 실무교육센터(오라클SQL,튜닝,힌트,자바프레임워크,안드로이드,아이폰,닷넷 실무개발강의)  


[기타 다른 강좌는 아래 해당 카테고리를 클릭해주세요]

2013년 10월 21일 월요일

자바 싱글톤, 쓰레드 예제 (Java Thread Singleton)

자바 싱글톤, 쓰레드 예제 (Java Thread Singleton)

public class Singleton {
    private static Singleton singleton = new Singleton();
    private Singleton() {
        System.out.println("Sington Class의 인스턴스 생성!");                   
    }
    public static Singleton getInstance() {       
        return singleton;
    }                                        
}
 
public class Main extends Thread {
    public static void main(String[] args) {
        System.out.println("Start.");       
        Singleton obj1 = Singleton.getInstance();
  Singleton obj2 = Singleton.getInstance();
        if (obj1 == obj2){
   System.out.println("obj1 == obj2");
        }
  else {
   System.out.println("obj1 != obj2");
  }
    }
}
 
=======================================
 
 
public class Singleton {
    private static Singleton singleton = null;
    private Singleton() {
        System.out.println("인스턴스 생성...");
        slowdown();                            
    }
    public static Singleton getInstance() {
        if (singleton == null) {
            singleton = new Singleton();
        }
        return singleton;
    }
    private void slowdown() {                  
        try {                                  
            Thread.sleep(10);                
        } catch (InterruptedException e) {     
        }                                      
    }                                          
}
 
 
public class Main extends Thread {
    public static void main(String[] args) {
        System.out.println("Start.");
        new Main("A").start();
        new Main("B").start();
        new Main("C").start();
        System.out.println("End.");
    }
    public void run() {
        Singleton obj = Singleton.getInstance();
        System.out.println(getName() + ": obj = " + obj);
    }
    public Main(String name) {
        super(name);
    }
}

2013년 10월 17일 목요일

자바 상속(java inheritance) 상속은 IS-A 관계

자바 상속(java inheritance)
 
상속은 IS-A 관계(하위클래스는 완벽한 상위클래스)
상위 클래스의 모든 내용을 하위 클래스가 계승한다.
하위 클래스는 상속된 필드와 메소드 중에 private으로 선언된 것이 아닌 것에만 접근할 수 있다.
(private으로 선언된것도 상속되지만 단지 접근 못할 뿐)
원시 코드 및 외부 인터페이스 재사용
하위 클래스는 상위클래스를 처다볼 수 잇지만 상위클래스는 하위클래스가 여러 개가 될 수 있으므로 정할 수 없다.
상위 클래스는 오직 한 개만 존재(자바는 단일 상속, C++의 경우 여러 개의 상위 클래스가 존재할 수 있다)
상위클래스 자체 및 변수, 메쏘드의 재사용
 

[예제]
 
package onj;
class A
{
    int f;          // 인스턴스 변수
    void m() { System.out.println("m()"); }      // 인스턴스 메쏘드
    static int sf;  // 클래스 변수
    static void sm() { 
     System.out.println("A sm()"); 
    } // 클래스 메쏘드
}
class InheritanceTest extends A
{
    int f2;
    void m2() { 
     System.out.println("B sm()"); 
    }
    
    public static void main(String[] args)
    {
     InheritanceTest b = new InheritanceTest();
        b.f2++; // InheritanceTest의 필드
        b.m2(); // InheritanceTest의 메쏘드
        b.f++; // A로부터 상속된InheritanceTest의 필드
        b.m(); // A로부터 상속된 InheritanceTest의 인스턴스 메쏘드
        InheritanceTest.sf++; // A로부터 상속된 클래스 필드
        InheritanceTest.sm(); // A로부터 상속된 클래스 메쏘드       
    }
}

 
 
[결과]
 
B sm()
m()
A sm()

오라클자바커뮤니티에서 설립한 개발자교육6년차 오엔제이프로그래밍 실무교육센터
(오라클SQL,튜닝,힌트,자바프레임워크,안드로이드,아이폰,닷넷 실무개발강의)  



2013년 8월 5일 월요일

(오라클자바교육,ORACELJAVA강좌)JAVA Swing과 JDBC(오라클)를 이용한 예제

//오라클의 EMP Table의 데이터를 가지고 화면에 뿌리는 예제
//이름을 입력하고 Enter Key를 누르면 JDBC를 이용하여  데이터를 가지고 옵니다.


오라클자바커뮤니티에서 설립한 오엔제이프로그래밍 실무교육센터
(오라클SQL, 튜닝, 힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷 실무전문 강의) 
 www.onjprogramming.co.kr  


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;

class DBTest {
        JTextField name;    JPasswordField tel;  JTextField addr;
        public DBTest() {
                JFrame f = new JFrame();
                Container cp = f.getContentPane();
                cp.setLayout(new FlowLayout());
                name = new JTextField("",10);
                name.setCaretColor(Color.blue);
                tel  = new JPasswordField("",10);
               
                                tel.setEditable(false);
                addr = new JTextField("",10);
                addr.setEditable(false);
                cp.add(new JLabel("성명 : "));        cp.add(name);
                cp.add(new JLabel("전화번호 : ")); cp.add(tel);
                cp.add(new JLabel("주소 : "));        cp.add(addr);

                name.addActionListener( new ActionListener()
                        {
                                public void actionPerformed(ActionEvent ae) {
                                        dataGet();
                                }
                        }
                );
                f.setSize(600, 100);                f.setVisible(true);
        }
       
                public static void main(String[] args) {
                new DBTest();       
        }

        public void dataGet() {
                Connection con=null;
                Statement stmt=null;
                ResultSet rs=null;
                try {
              Class.forName("oracle.jdbc.driver.OracleDriver");                       
                  con = DriverManager.getConnection("jdbc:oracle:thin:@***.***.***.***:1521:WINK", "test", "test");
                  stmt = con.createStatement();
                  rs = stmt.executeQuery("select tel, addr from emp where name = " + "'" + name.getText().trim() + "'");
                  if (rs!=null) {

                                            rs.next();
                          tel.setText(rs.getString("tel"));
                          addr.setText(rs.getString("addr"));
                  }
                }
                catch(Exception e) {System.out.println(e);}
                finally {
                        try        {
                                if (con != null) {con.close();        }
                        }
                        catch (Exception e){}
                }
        }
}