1. MSSQL 같은 경우 driver를 직접 홈페이지에서 받아야 하지만, Oracle같은 경우는 설지할 때 설치경로의 jdbc 폴더 내에 압축파일로 저장되어있다. (ojdbc14.jar)

 1) JAVA에서 외부 프로그램의 드라이버를 저장하는 곳이 따로 있다. 바로,

 C:\Program Files\Java\jdk1.6.0_23\jre\lib\ext\ 아래에 복사하여 넣어둔다.

 2) 일반 사용자의 경우에는 

  C:\Program Files\Java\jre6\lib\ext\ 에 넣어둔다.


2. Eclipse 환경에서는 JDBC를 사용할 프로젝트만 Build Path 의 ADD external Archives에서 추가하면된다.



3. Eclipse 에서 Oracle Plug in 설치.

 1)http://quantum.sourceforge.net/    에서 플러그인을 다운

 2)com.quantum.feature_3.3.9_update_site_format.jar  의 압축을 푼다.

 3)그 폴더를 이클립스에서 help-Install new software... 에서 ADD한 후 local에 압축 푼 플러그인을 선택한다.

 4)프로그램을 재시작하여 Window-Perspective-Other.. 에 보면 Quantum DB를 선택할 수 있다. 

 5)이후 Database Bookmarks에 원하는 db를 추가하여 연결 할 수 있다. 드라이버는 oracle.jdbc.diver.OracleDriver를 선택.









ps-----------------------------------------------------------------------------


1) JDBC에서의 index는 Java에서 특별하게 1부터 시작한다.

'Programming > JAVA' 카테고리의 다른 글

이클립스 JSP plug in / 환경설정  (3) 2011.03.24
JDBC 문법  (2) 2011.03.24
JAVA IO  (1) 2011.03.24
JAVA Threads  (2) 2011.03.24
Java Call by value, Call by reference  (2) 2011.03.24

1. ASCII vs Unicode 

 1) xxx stream : 8비트

 2) xxx Reader, xxx Writer : 16비트 


2. Stream방식 vs RandomAccess 방식

 1) Stream : 파일을 순차적으로 나열하기 때문에 접근속도의 문자가있을 수 있다.

 2) RandomAccess : 파일을 랜덤하게 나열하고 키 로 접근할 수 있다.


3. File의 내용 vs Meta data

 1) 파일의 내용을 처리 할 것인가..

 2) 파일에 대한 정보를 처리 할 것인가..

----------------------------------------------------------------------------------------------

 

4. Stream

 1) Sesqence : 순차적이다

 2) Concurrency : 동시성이 없다.

 3) 동시성을 주기위해 Randeom Access 방식을 사용한다.


5. File~~stream : 모두 String 형태로 저장/로드 된다

 1) 파일 스트림에서 한글을 읽을때.

 FileInputStream fis = new FileInputStream(file);
  int readCount =0;
  byte[] buffer = new byte [1024]; // 한글을 읽어야 할 수 있기 때문에 바이트로 받는다. 배열의 크기는 OS 시스템에 맞게 1024정도를 준다. (한번에 1024바이트를 읽는다)
  while((readCount=fis.read(buffer))>=0){
   area.append(new String(buffer,0,readCount));
  }


6. Data~~stream : 데이터형이 유지된다 (int, double...)

 1) 데이터에서 한글을 읽을때

  DataOutputStream dos = null;
//  FileOutputStream fos = null;
  try{
  // fos = new FileOutputStream("D:\\data.dat");
   dos = new DataOutputStream(new FileOutputStream("D:\\data.dat")); //생성자 안에 생성자를 넣어 간소화 (하나만 close()할 수 있다)
   dos.writeBoolean(false);
   dos.writeInt(100);
   dos.writeDouble(89.0);
   dos.writeUTF("hello world");
   dos.writeUTF("안뇽하세염");  // 파일을 열어보면 글자가 깨져서 보이게된다.
  // dos.writeUTF("ㅋㅋㅋ");  //UTF를 지원하기때문에 한글은 UTF를 사용한다.
   System.out.println("파일 저장 완료~!");

 

7. InputStreamReader : 캐릭터형 문자를 바이트형으로 변환하여 받는다 (한글을 받을 수 있다)

 

 System.out.print("당신은 어떤 계절을 좋아하시나요?");
    BufferedReader br = null;
  String season = null;
  try{
   br = new BufferedReader(new InputStreamReader(System.in));  // 
   season =br.readLine();
   System.out.println(season);
   try{
    br.close();  //반드시 닫아야한다
    }catch(IOException ex){}
  }catch(IOException ex){
   
  }

 

8. RandomAccessFile : 파일을 동시에 읽으며 쓰는게 가능하지만 한글처리가 힘들다.

 1) long getFilePointer() : 파일의 위치를 가져온다.

 2) void seek(long pos) : 파일의 원하는 부위에 포인터를 가져다 놓을 수 있다.

 3) long length() : 파일의 길이를 가져온다. End of Point 를 알 수 있다.

 

 4) 한글과 영문을 변환 할 수 있도록 하는 메소드를 만든다.

 package StreamDemo;
import java.io.UnsupportedEncodingException;
public class CharacterConversion {
 public static String entoko(String en){
  String ko = null;
  try{
   ko = new String(en.getBytes("ISO8859_1"),"KSC5601"); //KSC5601 은 ANCI 형 이고, UTF-8은 바꿔 쓰면된다.
  }catch(UnsupportedEncodingException ex){
  }
  return ko;
 }
 public static String kotoen(String ko){
  String en = null;
  try{
   ko = new String(ko.getBytes("KSC5601"),"ISO8859_1");
  }catch(UnsupportedEncodingException ex){
  }
  return en;
 }
}

 

 

 

9. 문자를 파싱(Parsing)하는 3가지방법

 import java.util.Scanner;
// 문자 파싱하는 방법 3가지
public class ScannerDemo {
 public static void main(String[] args) {
  String line = "1101    조성모    45  78  23  100";
  //1. String class's split()
  String [] array = line.split("\\s+");
  //2. java.util.StringTokenizer 
  java.util.StringTokenizer st = new java.util.StringTokenizer(line);
  String [] array1 = new String[st.countTokens()];
  int i = 0;
  while(st.hasMoreElements()){
   array1[i++] = st.nextToken();
  }  
  //3. Scanner 쓰자.
  Scanner scan = new Scanner(line).useDelimiter("\\s+");
  while(scan.hasNext()){
   System.out.println(scan.next());
  }
  
 }
}

 

 

 

10. 직렬화 (Serializtion)

 1) 데이터를 Object형 째로 읽고 쓰는게 가능하다.

 2) 프리미티브 타입은 모두 직렬화가 가능하다. (모든 객체가 Serialization 가능한 것은 아니다.)

 3) Serializable 인터페이스를 상속받은 클래스만 가능하다. (Flag Interface) (String, Vector, ArrayList 등등...)

 4) transient private String author; 로 직렬화에 제외시킬 수 도 있다.

 5) Externalizable 인터페이스를 상속하여 직렬화 할 것만 선택 할 수도 있다.

 

 

11. JAVA NIO

 1) ByteBuffer

  - allocateDirect() : 직접 OS의 메모리에 접근 할 수 있는 입/출력 방식.

 

 

 

 

ps---------------------------------------------------------------

1. os별 파일과 경로 구분선 알아내는 방법

      System.getProperty("file.separator") // os에 종속적인 파일 구분선
      File.separator // os에 종속적이지 않은 구분선.
  

      System.getProperty("path.separator") // 경로 구분선
      File.pathSeparator

'Programming > JAVA' 카테고리의 다른 글

JDBC 문법  (2) 2011.03.24
JDBC 설정  (2) 2011.03.24
JAVA Threads  (2) 2011.03.24
Java Call by value, Call by reference  (2) 2011.03.24
The AWT Component Library  (1) 2011.03.24

1. 쓰레드의 생성

 1) 쓰레드를 사용할려면 Thread를 상속받아 run()를 오버라이드하고 실행은 start()로 한다.

 2) run() 할 메소드에 Runnable 인터페이스를 상속받아 run()을 구현하고, 실행하는 곳에서는 start()를 하지 못하기 때문에 Thread를 생성해야 한다. Thread t1 = new Thread(runnable 인터페이스를 상속받은 클래스);


2. 쓰레드의 종료

 1) run() 내부의 작업을 반복문으로 만들어 조건으로 종료를 시킬 수 있다.

 2) exception(예외처리) 으로 해결하는 방법.

  -  시작한 곳에서 종료시 interrupt(); 명령으로 인터럽트를 발생시키면 종료된다.

 try{

while(!Thread.currentThread().isInterrupted()){

System.out.println("I'm alive..."+a);

Thread.sleep(10);

a++;

}

}catch(InterruptedException e){

}finally{

System.out.println("I'm dead....");

}


3. 쓰레드 관리

 1) sleep

 2) stop

 3) wait // synchronized()

'Programming > JAVA' 카테고리의 다른 글

JDBC 설정  (2) 2011.03.24
JAVA IO  (1) 2011.03.24
Java Call by value, Call by reference  (2) 2011.03.24
The AWT Component Library  (1) 2011.03.24
The AWT Event Model  (0) 2011.03.24

 

http://trypsr.tistory.com/74

에서 아주 잘 정리하셨길래 퍼왔음.

 

테스트 없이 눈으로만 코딩할 때 가장  쉬운 부분이 call by value 와 call by refence 를  이해하지 못할 때 생기는 오류가 아닐까 싶다.

기본형과 객체가  기본형은 call by value 이고 객체는 call by refence 라는  대부분의 java 개발자들이 알고 있을꺼라 생각한다.

그 예로 swap  가장 많이 설명하는데..

예제 1) 

class Test {
    private static void swap(int a, int b) {
        int temp = a;
        a = b;
        b = temp;
    }

    public static void main(String args[]) {
        int a = 1;
        int b = 2;

        System.out.println("a => " + a);
        System.out.println("b => " + b);

        swap(a, b);

        System.out.println("------- swap 후 -------");

        System.out.println("a => " + a);
        System.out.println("b => " + b);
    }
}

예제 1 의  원하던 결과가 아닌 것을 바로 알아 낼 수 있을 것이다.
 메소드에 넘기는 것은 reference 가 아닌 value 이기 때문에...
쉽다.  

다음 예제 2 를 보자
예제 2)

class Test {
    private static void swap(Integer a, Integer b) {
        Integer temp = a;
        a = b;
        b = temp;
    }

    public static void main(String args[]) {
        Integer a = new Integer(1);
        Integer b = new Integer(2);

        System.out.println("a => " + a.intValue());
        System.out.println("b => " + b.intValue());

        swap(a, b);

        System.out.println("------- swap 후 -------");

        System.out.println("a => " + a.intValue());
        System.out.println("b => " + b.intValue());
    }
}

예제 2  경우 Integer 는 Object 이다. Object 는 call by reference  
따라서 위의 예제는 원하는 결과를 가져올 것이다.
그러나 실행을 하면 예제 1과 전혀 다르지 않다는 것을 알  있다.

왜? 객체는 call by reference 라며 사기친거야?

 말하면 객체는 call by reference 맞다

그러나 해당 객체를  새로운 reference 를 참조해서 넘기는 것이다.

따라서 동일한 객체를  있지만 
main 에서의 reference 값과 swap 함수에서의 reference 값은  

따라서 위의 예제의 경우 원하는 결과가 나오지 않는다.

  이부분이 가장 이해가 힘들었는데, 즉 메소드에서 변수의 주소를 받았다 하더라도 실제 메소드 안에서 실행될때는 지역변수일 뿐입니다. 즉, 메소드를 벗어나게 되면 영향력이 없어지는 것이죠..

그래서 영향력이 있을때인 메소드 안에서 직접 그 주소의 값을 변경하면 영향을 받지만, 그런것이 아닌 단순한 주소의 복사는, 그 메소드 안에있는 지역변수의 변화일 뿐 실제 값에는 영향이 없습니다.


 어떻게 해야 해?

예제 3 을 보자.

예제 3)

class Test {
    int value;

    Test(int value) {
        this.value = value;
    }

    private static void swap(Test a, Test b) {
        int temp = a.value;
        a.value = b.value;
        b.value = temp;
    }

    public static void main(String args[]) {
        Test a = new Test(1);
        Test b = new Test(2);

        System.out.println("a => " + a.value);
        System.out.println("b => " + b.value);

        swap(a, b);

        System.out.println("------- swap 후 -------");

        System.out.println("a => " + a.value);
        System.out.println("b => " + b.value);
    }
}

예제 2와 같이 객체의 reference 를 넘긴다.
reference 를 직접  게 아니라.
reference 가 참조하는 객체의 value 를 변경하고 있다.
 같은 객체를 보고 있는 main 에서도 값이 바뀌는 것을 알  있다.

call by reference

해당 객체의 주소값을 직접 넘기는 게 아닌 객체를 보는 또 다른 주소값을 만들어서 넘기다는 사실을 잊지 말자~

 

'Programming > JAVA' 카테고리의 다른 글

JAVA IO  (1) 2011.03.24
JAVA Threads  (2) 2011.03.24
The AWT Component Library  (1) 2011.03.24
The AWT Event Model  (0) 2011.03.24
Building GUIs & Java Graphics  (0) 2011.03.24

+ Recent posts