메뉴 건너뛰기

tnt_lang

jsp/java batch 작업

박상현 2002.02.13 00:40 조회 수 : 1982 추천:22

웹에서 발견한 소스입니다..
유용하게 쓰일수도 있을것 같아 올립니다.
사이트 url;
http://home.clara.net/dwotton/dba/java_insert/test3.txt

소스코드
/*
   test3.java
   ----------

   This java class demonstrates inserting 500,000 rows into a table, one row at
   a time. With just a single commit at the end of the entire job.

   Auto-commit is switched off.

   Bind variables are used for the insert statements. This reduces parsing effort.

   You will need to change a few constants (database name, schema owner, etc.) before
   running this program in your environment. See the code below for details.

   compile using:

       set CLASSPATH=.;C:oracleora81jdbclibclasses111.zip

       javac test3.java



   Written: 18/10/01, Dave Wotton
            For more information about this test, including results and conclusions,
            refer to http://home.clara.net/dwotton/dba/java_insert.htm
*/

import java.io.*;
import java.sql.*;
import java.util.*;
import java.text.*;

public class test3
{
     public static void main (String[] args) throws SQLException  
     {

        int recCount = 0;
        String record = null;

        // You will need to make the following substitutions before running the program:
        //
        //   server_ipname -> the IP name of your Oracle server
        //   oracle_sid    -> the SID of your Oracle instance
        //   Login         -> the owner of the schema holding the dave_test1 table
        //   Password      -> the schema owner's password.

        String connect_string   = "jdbc:oracle:thin:@server_ipname:1521:oracle_sid";
        String Login            = "scott";
        String Password         = "tiger";


        // create a Date variable ...

        java.util.Date now = new java.util.Date();

        // Define a dateformatter to display date variables ...

        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT);

        // Timestamp the start of the run ...

        long startTime = System.currentTimeMillis();

        // convert the startTime into Date format

        now.setTime(startTime);

        // and display the start of run stats

        System.out.println("Time now: " + df.format(now) );

        // Load Oracle driver ...

        DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
    
        // Connect to the database ...

        Connection conn =
            DriverManager.getConnection (connect_string, Login, Password );

        // Disable auto-commit ...

        conn.setAutoCommit (false);

        try {

           // define a buffered reader, connected to the file "dave_test.in" ...

           FileReader fr     = new FileReader("dave_test.in");
           BufferedReader br = new BufferedReader(fr);

           // define a string to hold the records returned by the buffered reader ...

           record = new String();

           // Prepare an Oracle statement (with bind variables) to perform the update ...

           PreparedStatement pstmt =
                conn.prepareStatement ("insert into dave_test1 values(?,?,?,?)" );


           // Do the real processing ...
           // ----------------------

           while ((record = br.readLine()) != null)
           {
              recCount++;

              // define a tokenizer to split the input record into fields, using ':' as
              // the delimiter.

              StringTokenizer st = new StringTokenizer(record, ":");

              String l_key  = st.nextToken();  // an integer
              String l_col1 = st.nextToken();  // a small word
              String l_col2 = st.nextToken();  // a digit in the range 0-6
              String l_col3 = st.nextToken();  // a long string

              // and insert the row into the database ...

              pstmt.setInt(1,Integer.parseInt( l_key.trim() ) );
              pstmt.setString(2,l_col1.trim() );
              pstmt.setInt(3,Integer.parseInt( l_col2.trim() ) );
              pstmt.setString(4,l_col3.trim() );

              pstmt.executeUpdate ();     // Do the update

              // if ( recCount > 100 ) { break; }
      
           }

           Statement stmt = conn.createStatement ();

           stmt.executeQuery ("commit");

           pstmt.close();    // close the prepared statement object used for the inserts

           stmt.close();     // close the statement object used for the commit

           conn.close();     // close the database connection

           // Timestamp the end of the run ...

           long stopTime = System.currentTimeMillis();

           // Calculate the duration ...

           long runTime = stopTime - startTime;

           // convert to mm:ss ...

           long mins = runTime / 60000;

           long secs = ( runTime % 60000 ) / 1000;

           String mins_str = mins + "" ;

           if ( mins_str.length() == 1 ) { mins_str = '0' + mins_str; }

           String secs_str = secs + "";

           if ( secs_str.length() == 1 ) { secs_str = '0' + secs_str; }

           String Duration = mins_str + ":" + secs_str;

           // convert the stopTime into Date format

           now.setTime(stopTime);

           // and display the end of run stats

           System.out.println("Time now: " + df.format(now) + " Run time: " + runTime + "ms (" + Duration + ")" );

        } catch (IOException e) {
           // catch possible io errors from readLine()
           System.out.println("Uh oh, got an IOException error!");
           e.printStackTrace();
        }

    } // end of main

} // end of class
번호 제목 글쓴이 날짜 조회 수
21 JAVA - 한글 인코딩 변환 체크 한방에 끝내기 총관리자 2014.06.07 844
20 clshoesfashionc4u nacyrobert 2013.03.15 1790
19 JMSN messenger-한글지원(2/2) file 박상현 2003.12.16 2226
18 JMSN messenger-한글지원(1/2) file 박상현 2003.12.16 2303
17 ty*bizware for java sample file 운영자 2003.04.02 2284
16 자바교재소스 운영자 2003.01.29 2269
15 PDFBox 0.6.1 - Java PDF Library 운영자 2003.04.15 4234
14 [struts]폼빈에 배열을 사용하기 박상현 2006.05.20 2312
13 클래스 패스와 관련한 문제는 요 jsp 하나로.. 해결 끝이네요.. 하늘과컴 2005.11.15 2228
12 weblogic8.1과 eclipse3.0RC2, LombozRC1용을 이용한 EJB개발 박상현 2004.06.22 2485
11 weblogic5.1과 ant를 이용하여 EJB개발(내부 개발용) 박상현 2004.06.22 5264
10 orion와 eclipse을 이용하여 EJB개발시 참고(내부개발용) 박상현 2004.06.22 2385
9 한글처리 방법/절차 이해 박상현 2003.10.20 1873
8 정수값을 3자리수마다 컴마를 찍기 박상현 2003.10.13 2121
7 시간안에 응답하지 않는함수는 에러(혹은 exception)처리 박상현 2003.10.08 1966
» batch 작업 박상현 2002.02.13 1982
5 수정된 StringTokenizer 박상현 2001.12.17 2518
4 java에서 system의 property확인 jsp파일 박상현 2001.10.27 2279
3 프리페어스테이트먼트에 ? 표 자리에 값을 셋팅후 만들어진 SQL 문을 보는 유틸 운영자 2003.09.18 3244
2 RAS암호 시스템의 구현 박상현 2001.10.16 3176
위로